コード例 #1
0
        public void GetMiningTimestamp()
        {
            var tool = new KeyTool(new DataFolder(string.Empty));
            Key key  = tool.GeneratePrivateKey();

            this.network = new TestPoANetwork(new List <PubKey>()
            {
                tool.GeneratePrivateKey().PubKey, key.PubKey, tool.GeneratePrivateKey().PubKey
            });

            FederationManager fedManager = PoATestsBase.CreateFederationManager(this, this.network, new ExtendedLoggerFactory());

            this.slotsManager = new SlotsManager(this.network, fedManager, new LoggerFactory());

            List <PubKey> fedKeys    = this.federationManager.GetFederationMembers();
            uint          roundStart = this.consensusOptions.TargetSpacingSeconds * (uint)fedKeys.Count * 5;

            fedManager.SetPrivatePropertyValue(nameof(FederationManager.IsFederationMember), true);
            fedManager.SetPrivatePropertyValue(nameof(FederationManager.FederationMemberKey), key);

            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart));
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart + 4));

            roundStart += this.consensusOptions.TargetSpacingSeconds * (uint)fedKeys.Count;
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart - 5));
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart - this.consensusOptions.TargetSpacingSeconds + 1));

            Assert.True(this.slotsManager.IsValidTimestamp(this.slotsManager.GetMiningTimestamp(roundStart - 5)));
        }
コード例 #2
0
        public void GetMiningTimestamp()
        {
            var tool = new KeyTool(null);
            Key key  = tool.GeneratePrivateKey();

            this.network = new TestPoANetwork(new List <PubKey>()
            {
                tool.GeneratePrivateKey().PubKey, key.PubKey, tool.GeneratePrivateKey().PubKey
            });

            var fedManager = new FederationManager(NodeSettings.Default(this.network), this.network, new LoggerFactory());

            this.slotsManager = new SlotsManager(this.network, fedManager, new LoggerFactory());

            List <PubKey> fedKeys    = this.consensusOptions.FederationPublicKeys;
            uint          roundStart = this.consensusOptions.TargetSpacingSeconds * (uint)fedKeys.Count * 5;

            fedManager.SetPrivatePropertyValue(nameof(FederationManager.IsFederationMember), true);
            fedManager.SetPrivatePropertyValue(nameof(FederationManager.FederationMemberKey), key);

            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart));
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart + 4));

            roundStart += this.consensusOptions.TargetSpacingSeconds * (uint)fedKeys.Count;
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart - 5));
            Assert.Equal(roundStart + this.consensusOptions.TargetSpacingSeconds, this.slotsManager.GetMiningTimestamp(roundStart - this.consensusOptions.TargetSpacingSeconds + 1));

            Assert.True(this.slotsManager.IsValidTimestamp(this.slotsManager.GetMiningTimestamp(roundStart - 5)));
        }
コード例 #3
0
 public PoANodeRunnerWithCounterchain(string dataDir, PoANetwork network, Network counterChain, EditableTimeProvider timeProvider)
     : base(dataDir, null)
 {
     this.Network      = network;
     this.timeProvider = timeProvider;
     this.counterChain = counterChain;
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: georgepinca/src
        public static async Task Main(string[] args)
        {
            try
            {
                Network network      = new PoANetwork();
                var     nodeSettings = new NodeSettings(args: args, network: network);

                bool keyGenerationRequired = nodeSettings.ConfigReader.GetOrDefault("generateKeyPair", false);
                if (keyGenerationRequired)
                {
                    GenerateFederationKey(nodeSettings.DataFolder);
                    return;
                }

                IFullNode node = new FullNodeBuilder()
                                 .UseNodeSettings(nodeSettings)
                                 .UseBlockStore()
                                 .UsePoAConsensus()
                                 .UseMempool()
                                 .UseWallet()
                                 .UseApi()
                                 .UseApps()
                                 .AddRPC()
                                 .Build();

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem running the node. Details: '{0}'", ex.ToString());
            }
        }
コード例 #5
0
        public SlotsManagerTests()
        {
            this.network          = new TestPoANetwork();
            this.consensusOptions = this.network.ConsensusOptions;

            this.federationManager = PoATestsBase.CreateFederationManager(this);
            this.slotsManager      = new SlotsManager(this.network, this.federationManager, new LoggerFactory());
        }
コード例 #6
0
        public static bool IsPollExpiredAt(Poll poll, ChainedHeader chainedHeader, PoANetwork network)
        {
            if (chainedHeader == null)
            {
                return(false);
            }

            return(Math.Max(poll.PollStartBlockData.Height + network.ConsensusOptions.PollExpiryBlocks, network.ConsensusOptions.Release1100ActivationHeight) <= chainedHeader.Height);
        }
コード例 #7
0
        public SlotsManagerTests()
        {
            this.network          = new TestPoANetwork();
            this.consensusOptions = this.network.ConsensusOptions;

            var fedManager = new FederationManager(NodeSettings.Default(this.network), this.network, new LoggerFactory());

            this.slotsManager = new SlotsManager(this.network, fedManager, new LoggerFactory());
        }
コード例 #8
0
 public JoinFederationRequestService(ICounterChainSettings counterChainSettings, IFullNode fullNode, IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, Network network, NodeSettings nodeSettings, VotingManager votingManager)
 {
     this.counterChainSettings = counterChainSettings;
     this.fullNode             = fullNode;
     this.httpClientFactory    = httpClientFactory;
     this.loggerFactory        = loggerFactory;
     this.network       = network as PoANetwork;
     this.nodeSettings  = nodeSettings;
     this.votingManager = votingManager;
 }
コード例 #9
0
        public CoreNode CreatePoANode(PoANetwork network, Key key)
        {
            string   dataFolder = this.GetNextDataFolderName();
            CoreNode node       = this.CreateNode(new PoANodeRunner(dataFolder, network, this.TimeProvider), "poa.conf");

            var settings = new NodeSettings(network, args: new string[] { "-conf=poa.conf", "-datadir=" + dataFolder });
            var tool     = new KeyTool(settings.DataFolder);

            tool.SavePrivateKey(key);

            return(node);
        }
コード例 #10
0
        public PollsRepository(ChainIndexer chainIndexer, DataFolder dataFolder, DBreezeSerializer dBreezeSerializer, PoANetwork network)
        {
            Guard.NotEmpty(dataFolder.PollsPath, nameof(dataFolder.PollsPath));

            Directory.CreateDirectory(dataFolder.PollsPath);
            this.chainIndexer      = chainIndexer;
            this.dbreeze           = new DBreezeEngine(dataFolder.PollsPath);
            this.dBreezeSerializer = dBreezeSerializer;
            this.network           = network;

            this.logger = LogManager.GetCurrentClassLogger();
        }
コード例 #11
0
        public static Block CreateBlock(PoANetwork network, Transaction transaction, int height)
        {
            Block block = new Block();

            if (transaction != null)
            {
                block.Transactions.Add(transaction);
            }

            block.Header.Time = (uint)(height * network.ConsensusOptions.TargetSpacingSeconds);

            block.UpdateMerkleRoot();
            block.GetHash();

            return(block);
        }
コード例 #12
0
        public PoARulesTestsBase(PoANetwork network = null)
        {
            this.loggerFactory    = new LoggerFactory();
            this.network          = network == null ? new PoANetwork() : network;
            this.consensusOptions = this.network.ConsensusOptions;

            this.chain = new ConcurrentChain(this.network);
            IDateTimeProvider timeProvider = new DateTimeProvider();

            this.consensusSettings = new ConsensusSettings(NodeSettings.Default(this.network));

            this.slotsManager = new SlotsManager(this.network, new FederationManager(NodeSettings.Default(this.network), this.network, this.loggerFactory), this.loggerFactory);

            this.poaHeaderValidator = new PoABlockHeaderValidator(this.loggerFactory);

            this.rulesEngine = new PoAConsensusRuleEngine(this.network, this.loggerFactory, new DateTimeProvider(), this.chain,
                                                          new NodeDeployments(this.network, this.chain), this.consensusSettings, new Checkpoints(this.network, this.consensusSettings), new Mock <ICoinView>().Object,
                                                          new ChainState(), new InvalidBlockHashStore(timeProvider), new NodeStats(timeProvider), this.slotsManager, this.poaHeaderValidator);

            List <ChainedHeader> headers = ChainedHeadersHelper.CreateConsecutiveHeaders(50, null, false, null, this.network);

            this.currentHeader = headers.Last();
        }
コード例 #13
0
        public override void Initialize()
        {
            base.Initialize();

            this.network = this.Parent.Network as PoANetwork;
        }
コード例 #14
0
 public CoreNode CreatePoANode(PoANetwork network)
 {
     return(this.CreateNode(new PoANodeRunner(this.GetNextDataFolderName(), network, this.TimeProvider), "poa.conf"));
 }
コード例 #15
0
 public static ChainedHeaderBlock[] GetEmptyBlocks(ChainIndexer chainIndexer, PoANetwork network, int count)
 {
     return(GetBlocks(count, chainIndexer, i => CreateBlock(network, chainIndexer.Tip.Height + 1), chainIndexer.Tip));
 }
コード例 #16
0
 public PoANodeRunner(string dataDir, PoANetwork network, EditableTimeProvider timeProvider)
     : base(dataDir, null)
 {
     this.Network      = network;
     this.timeProvider = timeProvider;
 }
コード例 #17
0
        public static ChainedHeaderBlock CreateBlock(PoANetwork network, int height)
        {
            Block block = CreateBlock(network, network.CreateTransaction(), height);

            return(new ChainedHeaderBlock(block, new ChainedHeader(block.Header, block.GetHash(), height)));
        }