private void ApproveTx(BlockHeader parent, Transaction tx) { tx.Nonce = _stateReader.GetNonce(parent.StateRoot, tx.SenderAddress); _wallet.Sign(tx, _chainId); tx.Hash = tx.CalculateHash(); tx.Timestamp = _timestamper.EpochSeconds; }
public void should_return_valid_pending_and_queued_transactions() { uint nonce = 3; _stateReader.GetNonce(Arg.Any <Keccak>(), _address).Returns(new UInt256(nonce)); var transactions = GetTransactions(); _txPool.GetPendingTransactions().Returns(transactions); var info = _infoProvider.GetInfo(Build.A.BlockHeader.TestObject); info.Pending.Count.Should().Be(1); info.Queued.Count.Should().Be(1); var pending = info.Pending.First(); pending.Key.Should().Be(_address); pending.Value.Count.Should().Be(3); VerifyNonceAndTransactions(pending.Value, 3); VerifyNonceAndTransactions(pending.Value, 4); VerifyNonceAndTransactions(pending.Value, 5); var queued = info.Queued.First(); queued.Key.Should().Be(_address); queued.Value.Count.Should().Be(4); VerifyNonceAndTransactions(queued.Value, 1); VerifyNonceAndTransactions(queued.Value, 2); VerifyNonceAndTransactions(queued.Value, 8); VerifyNonceAndTransactions(queued.Value, 9); }
private UInt256 CalculateNonce(Address address, Keccak stateRoot, IDictionary <Address, UInt256> nonces) { if (!nonces.TryGetValue(address, out var nonce)) { nonce = _stateReader.GetNonce(stateRoot, address); } return(nonces[address] = ++nonce); }
public TxPoolInfo GetInfo(BlockHeader head) { var transactions = _txPool.GetPendingTransactions(); var groupedTransactions = transactions.GroupBy(t => t.SenderAddress); var pendingTransactions = new Dictionary <Address, IDictionary <ulong, Transaction> >(); var queuedTransactions = new Dictionary <Address, IDictionary <ulong, Transaction> >(); foreach (var group in groupedTransactions) { var address = group.Key; if (address == null) { continue; } var accountNonce = _stateProvider.GetNonce(head.StateRoot, address); var expectedNonce = accountNonce; var pending = new Dictionary <ulong, Transaction>(); var queued = new Dictionary <ulong, Transaction>(); var transactionsGroupedByNonce = group.OrderBy(t => t.Nonce); foreach (var transaction in transactionsGroupedByNonce) { var transactionNonce = (ulong)transaction.Nonce; if (transaction.Nonce < accountNonce) { queued.Add(transactionNonce, transaction); continue; } if (transaction.Nonce == accountNonce || accountNonce != expectedNonce && transaction.Nonce == expectedNonce) { pending.Add(transactionNonce, transaction); expectedNonce = transaction.Nonce + 1; continue; } queued.Add(transactionNonce, transaction); } if (pending.Any()) { pendingTransactions[address] = pending; } if (queued.Any()) { queuedTransactions[address] = queued; } } return(new TxPoolInfo(pendingTransactions, queuedTransactions)); }
public CallOutput CreateAccessList(BlockHeader header, Transaction tx, CancellationToken cancellationToken, bool optimize) { CallOutputTracer callOutputTracer = new(); AccessTxTracer accessTxTracer = optimize ? new(tx.SenderAddress, tx.GetRecipient(tx.IsContractCreation ? _stateReader.GetNonce(header.StateRoot, tx.SenderAddress) : 0)) : new(); (bool Success, string Error)tryCallResult = TryCallAndRestore(header, header.Number, header.Timestamp, tx, new CompositeTxTracer(callOutputTracer, accessTxTracer).WithCancellation(cancellationToken)); return(new CallOutput { Error = tryCallResult.Success ? callOutputTracer.Error : tryCallResult.Error, GasSpent = accessTxTracer.GasSpent, OutputData = callOutputTracer.ReturnValue, InputError = !tryCallResult.Success, AccessList = accessTxTracer.AccessList }); }
public async Task get_nonce_should_invoke_blockchain_bridge_get_nonce() { UInt256 nonce = 1; var address = TestItem.AddressA; _blockFinder.Head.Returns(_anyBlock); _stateReader.GetNonce(_anyBlock.StateRoot, address).Returns(nonce); var result = await _ndmBridge.GetNonceAsync(address); _stateReader.Received().GetNonce(_anyBlock.StateRoot, address); result.Should().Be(nonce); }
public TxPoolInfo GetInfo(BlockHeader head) { var groupedTransactions = _txPool.GetPendingTransactionsBySender(); var pendingTransactions = new Dictionary <Address, IDictionary <ulong, Transaction> >(); var queuedTransactions = new Dictionary <Address, IDictionary <ulong, Transaction> >(); foreach (KeyValuePair <Address, Transaction[]> group in groupedTransactions) { Address?address = group.Key; if (address is null) { continue; } var accountNonce = _stateReader.GetNonce(head.StateRoot, address); var expectedNonce = accountNonce; var pending = new Dictionary <ulong, Transaction>(); var queued = new Dictionary <ulong, Transaction>(); var transactionsOrderedByNonce = group.Value.OrderBy(t => t.Nonce); foreach (var transaction in transactionsOrderedByNonce) { ulong transactionNonce = (ulong)transaction.Nonce; if (transaction.Nonce == expectedNonce) { pending.Add(transactionNonce, transaction); expectedNonce = transaction.Nonce + 1; } else { queued.Add(transactionNonce, transaction); } } if (pending.Any()) { pendingTransactions[address] = pending; } if (queued.Any()) { queuedTransactions[address] = queued; } } return(new TxPoolInfo(pendingTransactions, queuedTransactions)); }
public Task <UInt256> GetNonceAsync(Address address) { return(Task.FromResult(_stateReader.GetNonce(_blockTree.Head.StateRoot, address))); }
private UInt256 GetNonce(Keccak stateRoot, Address address) { return(_stateReader.GetNonce(stateRoot, address)); }
public UInt256 GetNonce(Address address) => _stateReader.GetNonce(StateRoot, address);
public BigInteger GetNonce(Address address) { return(_stateReader.GetNonce(_blockTree.Head.StateRoot, address)); }