From 3cc01553e52916e6ca247a4907685a7697ca4d60 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 3 May 2017 10:27:42 +0200 Subject: [PATCH] Proof-of-concept test sync to solve colliding nonces --- internal/ethapi/api.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index f9eed87975..30ff4f97b4 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -25,6 +25,7 @@ import ( "math/big" "strings" "time" + "sync" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" @@ -1166,10 +1167,20 @@ func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c } return tx.Hash(), nil } +var nonceMutex sync.RWMutex // global mutex for locking chain operations + // SendTransaction creates a transaction for the given argument, sign it and submit it to the // transaction pool. func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args SendTxArgs) (common.Hash, error) { + + if args.Nonce == nil { + // We'll need to set nonce from pool, and thus we need to lock here + nonceMutex.Lock() + defer nonceMutex.Unlock() + + } + // Set some sanity defaults and terminate on failure if err := args.setDefaults(ctx, s.b); err != nil { return common.Hash{}, err