public void Execute(DeltaBuilderContext context) { context.ProducedDelta = new Delta { PreviousDeltaDfsHash = context.PreviousDeltaHash.ToArray().ToByteString(), DeltaNumber = context.PreviousDelta.DeltaNumber + 1, MerkleRoot = context.Candidate.Hash, CoinbaseEntries = { context.CoinbaseEntry }, PublicEntries = { context.Transactions }, GasUsed = (long)context.Transactions.Sum(x => x.GasLimit), TimeStamp = Timestamp.FromDateTime(_dateTimeProvider.UtcNow) }; if (_logger.IsEnabled(LogEventLevel.Information)) { _logger.Information("Built a delta {number} {hash} based on {previousHash} with {txCount} transactions", context.ProducedDelta.DeltaNumber, context.Candidate.Hash, context.ProducedDelta.PreviousDeltaDfsHash, context.ProducedDelta.PublicEntries.Count); } foreach (PublicEntry publicEntry in context.ProducedDelta.PublicEntries) { if (_logger.IsEnabled(LogEventLevel.Information)) { _logger.Information("Entry {from} -> {to} with nonce {nonce}", publicEntry.SenderAddress.ToAddress(), publicEntry.ReceiverAddress.ToAddress(), publicEntry.Nonce); } } }
public void Execute(DeltaBuilderContext context) { IList <PublicEntry> allTransactions = _retriever.GetMempoolTransactionsByPriority(); Guard.Argument(allTransactions, nameof(allTransactions)) .NotNull("Mempool content returned null, check the mempool is actively running"); IList <PublicEntry> includedTransactions = GetValidTransactionsForDelta(allTransactions); context.Transactions = includedTransactions; }
public void Execute(DeltaBuilderContext context) { if (_logger.IsEnabled(LogEventLevel.Debug)) { _logger.Debug("Resolving previous delta by hash ({previousHash})", context.PreviousDeltaHash); } if (!_deltaCache.TryGetOrAddConfirmedDelta(context.PreviousDeltaHash, out Delta previousDelta)) { throw new InvalidDataException("Cannot retrieve previous delta from cache during delta construction."); } context.PreviousDelta = previousDelta; }
public void Execute(DeltaBuilderContext context) { if (_logger.IsEnabled(LogEventLevel.Debug)) { _logger.Debug("Registering new delta with parent ({previousHash})", context.PreviousDeltaHash); } _deltaCache.AddLocalDelta(context.Candidate, context.ProducedDelta); // for easier delta tracking when testing truffle // if ((context.ProducedDelta.PublicEntries?.Count ?? 0) > 0) // { // _deltaCache.AddLocalDelta(context.Candidate, context.ProducedDelta); // } }
public void Execute(DeltaBuilderContext context) { byte[] salt = GetSaltFromPreviousDelta(context.PreviousDeltaHash); IEnumerable <RawEntryWithSaltedAndHashedEntry> rawAndSaltedEntriesBySignature = context.Transactions.Select(e => new RawEntryWithSaltedAndHashedEntry(e, salt, _hashProvider)); // (Eα;Oα) byte[] shuffledEntriesBytes = rawAndSaltedEntriesBySignature .OrderBy(v => v.SaltedAndHashedEntry, ByteUtil.ByteListComparer.Default) .SelectMany(v => v.RawEntry.ToByteArray()) .ToArray(); // dn byte[] signaturesInOrder = context.Transactions .Select(p => p.Signature.ToByteArray()) .OrderBy(s => s, ByteUtil.ByteListComparer.Default) .SelectMany(b => b) .ToArray(); // xf UInt256 summedFees = context.Transactions.Sum(t => t.GasPrice.ToUInt256() * t.GasLimit); //∆Ln,j = L(f/E) + dn + E(xf, j) context.CoinbaseEntry = new CoinbaseEntry { Amount = summedFees.ToUint256ByteString(), ReceiverPublicKey = _producerUniqueId.PublicKey.ToByteString() }; byte[] globalLedgerStateUpdate = shuffledEntriesBytes .Concat(signaturesInOrder) .Concat(context.CoinbaseEntry.ToByteArray()) .ToArray(); //hj CandidateDeltaBroadcast candidate = new CandidateDeltaBroadcast { // h∆j Hash = MultiBase.Decode(_hashProvider.ComputeMultiHash(globalLedgerStateUpdate).ToCid()) .ToByteString(), // Idj ProducerId = _producerUniqueId, PreviousDeltaDfsHash = context.PreviousDeltaHash.ToArray().ToByteString() }; context.Candidate = candidate; }
public void Execute(DeltaBuilderContext context) { var previousRoot = context.PreviousDelta.StateRoot; Keccak stateRoot = previousRoot.IsEmpty ? Keccak.EmptyTreeHash : new Keccak(previousRoot.ToByteArray()); if (_logger.IsEnabled(LogEventLevel.Debug)) { _logger.Error($"Running state calculation for delta {context.ProducedDelta.DeltaNumber}"); } // here we need a read only delta executor (like in block builders - everything reverts in the end) _stateProvider.StateRoot = stateRoot; _deltaExecutor.CallAndReset(context.ProducedDelta, NullTxTracer.Instance); _stateProvider.Reset(); }
///<inheritdoc /> public CandidateDeltaBroadcast BuildCandidateDelta(Cid previousDeltaHash) { DeltaBuilderContext context = new DeltaBuilderContext(previousDeltaHash); foreach (IDeltaBuilderStep step in _steps) { step.Execute(context); } // to simplify cases when we test truffle // if ((context.Transactions?.Count ?? 0) == 0) // { // return null; // } return(context.Candidate); }