diff --git a/eth/api_backend.go b/eth/api_backend.go index fe108d2720..1dcf4a2acf 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -40,8 +40,10 @@ import ( type EthApiBackend struct { eth *Ethereum gpo *gasprice.Oracle + localNonces map[common.Address] uint64 } + func (b *EthApiBackend) ChainConfig() *params.ChainConfig { return b.eth.chainConfig } @@ -160,7 +162,13 @@ func (b *EthApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) ( b.eth.txMu.Lock() defer b.eth.txMu.Unlock() - return b.eth.txPool.State().GetNonce(addr), nil + nonce, _ := b.localNonces[addr] + poolNonce := b.eth.txPool.State().GetNonce(addr) + if poolNonce > nonce{ + nonce = poolNonce + } + b.localNonces[addr] = nonce+1 + return nonce, nil } func (b *EthApiBackend) Stats() (pending int, queued int) { diff --git a/eth/backend.go b/eth/backend.go index f864b1d88b..1fc076dc1c 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -170,7 +170,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { eth.miner.SetGasPrice(config.GasPrice) eth.miner.SetExtra(makeExtraData(config.ExtraData)) - eth.ApiBackend = &EthApiBackend{eth, nil} + eth.ApiBackend = &EthApiBackend{eth, nil, make(map[common.Address] uint64)} gpoParams := config.GPO if gpoParams.Default == nil { gpoParams.Default = config.GasPrice diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index f9eed87975..f067dce06b 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -330,7 +330,6 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs } // Assemble the transaction and sign with the wallet tx := args.toTransaction() - var chainID *big.Int if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { chainID = config.ChainId @@ -1184,6 +1183,8 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen // Assemble the transaction and sign with the wallet tx := args.toTransaction() + log.Info("Assembled transaction", "fullhash", tx.Hash().Hex(), "nonce", tx.Nonce()) + var chainID *big.Int if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { chainID = config.ChainId