Proof-of-concept test with maintaining a local map of nonces

This commit is contained in:
Martin Holst Swende 2017-05-02 00:10:28 +02:00
parent f9be9a2302
commit 3398009440
3 changed files with 12 additions and 3 deletions

View file

@ -40,8 +40,10 @@ import (
type EthApiBackend struct { type EthApiBackend struct {
eth *Ethereum eth *Ethereum
gpo *gasprice.Oracle gpo *gasprice.Oracle
localNonces map[common.Address] uint64
} }
func (b *EthApiBackend) ChainConfig() *params.ChainConfig { func (b *EthApiBackend) ChainConfig() *params.ChainConfig {
return b.eth.chainConfig return b.eth.chainConfig
} }
@ -160,7 +162,13 @@ func (b *EthApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (
b.eth.txMu.Lock() b.eth.txMu.Lock()
defer b.eth.txMu.Unlock() 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) { func (b *EthApiBackend) Stats() (pending int, queued int) {

View file

@ -170,7 +170,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth.miner.SetGasPrice(config.GasPrice) eth.miner.SetGasPrice(config.GasPrice)
eth.miner.SetExtra(makeExtraData(config.ExtraData)) eth.miner.SetExtra(makeExtraData(config.ExtraData))
eth.ApiBackend = &EthApiBackend{eth, nil} eth.ApiBackend = &EthApiBackend{eth, nil, make(map[common.Address] uint64)}
gpoParams := config.GPO gpoParams := config.GPO
if gpoParams.Default == nil { if gpoParams.Default == nil {
gpoParams.Default = config.GasPrice gpoParams.Default = config.GasPrice

View file

@ -330,7 +330,6 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
} }
// Assemble the transaction and sign with the wallet // Assemble the transaction and sign with the wallet
tx := args.toTransaction() tx := args.toTransaction()
var chainID *big.Int var chainID *big.Int
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) {
chainID = config.ChainId chainID = config.ChainId
@ -1184,6 +1183,8 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
// Assemble the transaction and sign with the wallet // Assemble the transaction and sign with the wallet
tx := args.toTransaction() tx := args.toTransaction()
log.Info("Assembled transaction", "fullhash", tx.Hash().Hex(), "nonce", tx.Nonce())
var chainID *big.Int var chainID *big.Int
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) {
chainID = config.ChainId chainID = config.ChainId