示例#1
0
        public CliqueBlockProducer(
            ITransactionPool transactionPool,
            IBlockchainProcessor devProcessor,
            IBlockTree blockTree,
            IStateProvider stateProvider,
            ITimestamp timestamp,
            ICryptoRandom cryptoRandom,
            CliqueSealEngine cliqueSealEngine,
            CliqueConfig config,
            Address address,
            ILogManager logManager)
        {
            _logger          = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _transactionPool = transactionPool ?? throw new ArgumentNullException(nameof(transactionPool));
            _processor       = devProcessor ?? throw new ArgumentNullException(nameof(devProcessor));
            _blockTree       = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
            _stateProvider   = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider));
            _timestamp       = timestamp ?? throw new ArgumentNullException(nameof(_timestamp));
            _cryptoRandom    = cryptoRandom ?? throw new ArgumentNullException(nameof(_cryptoRandom));
            _sealEngine      = cliqueSealEngine ?? throw new ArgumentNullException(nameof(_sealEngine));
            _config          = config ?? throw new ArgumentNullException(nameof(_config));
            _address         = address ?? throw new ArgumentNullException(nameof(_address));

            if (_sealEngine.CanSeal)
            {
                _timer.AutoReset = false;
                _timer.Elapsed  += TimerOnElapsed;
                _timer.Interval  = 100;
                _timer.Start();
            }
        }
示例#2
0
 internal Snapshot(CliqueConfig config, LruCache <Keccak, Address> sigCache, UInt256 number, Keccak hash, SortedList <Address, UInt256> signers, Dictionary <Address, Tally> tally)
 {
     Config   = config;
     SigCache = sigCache;
     Number   = number;
     Hash     = hash;
     Signers  = new SortedList <Address, UInt256>(signers, CliqueAddressComparer.Instance);
     Votes    = new List <Vote>();
     Tally    = tally;
 }
示例#3
0
        public CliqueSealEngine(CliqueConfig config, IEthereumSigner signer, PrivateKey key, IDb blocksDb, IBlockTree blockTree, ILogManager logManager)
        {
            _logger    = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _config    = config ?? throw new ArgumentNullException(nameof(config));
            _blocksDb  = blocksDb ?? throw new ArgumentNullException(nameof(blocksDb));
            _signer    = signer ?? throw new ArgumentNullException(nameof(signer));
            _blockTree = blockTree ?? throw new ArgumentNullException();
            _key       = key ?? throw new ArgumentNullException(nameof(key));

            if (config.Epoch == 0)
            {
                config.Epoch = Clique.DefaultEpochLength;
            }
        }
示例#4
0
        public static Snapshot LoadSnapshot(CliqueConfig config, LruCache <Keccak, Address> sigCache, IDb db, Keccak hash)
        {
            Keccak key = GetSnapshotKey(hash);

            byte[] blob = db.Get(key);
            if (blob == null)
            {
                return(null);
            }

            SnapshotDecoder decoder  = new SnapshotDecoder();
            Snapshot        snapshot = decoder.Decode(blob.AsRlpContext());

            snapshot.Config   = config;
            snapshot.SigCache = sigCache;
            return(snapshot);
        }
示例#5
0
        public Snapshot Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            context.ReadSequenceLength();

            // Config
            CliqueConfig config = new CliqueConfig(15, 30000);
            // Signature cache
            LruCache <Keccak, Address> sigCache = new LruCache <Keccak, Address>(Clique.InMemorySignatures);
            // Block number
            UInt256 number = context.DecodeUInt256();
            // Hash
            Keccak hash = context.DecodeKeccak();
            // Signers
            SortedList <Address, UInt256> signers = DecodeSigners(context);
            // Votes
            List <Vote> votes = DecodeVotes(context);
            // Tally
            Dictionary <Address, Tally> tally = DecodeTally(context);
            Snapshot snapshot = new Snapshot(config, sigCache, number, hash, signers, tally);

            snapshot.Votes = votes;

            return(snapshot);
        }
示例#6
0
 internal Snapshot(CliqueConfig config, LruCache <Keccak, Address> sigCache, UInt256 number, Keccak hash, SortedList <Address, UInt256> signers)
     : this(config, sigCache, number, hash, signers, new Dictionary <Address, Tally>())
 {
 }