Skip to content

Commit

Permalink
internal/ethapi: error if tx args includes chain id that doesn't matc…
Browse files Browse the repository at this point in the history
…h local (ethereum#25157)

* internal/ethapi: error if tx args includes chain id that doesn't match local

* internal/ethapi: simplify code a bit

Co-authored-by: Péter Szilágyi <[email protected]>
  • Loading branch information
2 people authored and blakehhuynh committed Oct 7, 2022
1 parent 6f93ff9 commit ecad8d6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
args.Gas = &estimated
log.Trace("Estimate gas usage automatically", "gas", args.Gas)
}
if args.ChainID == nil {
id := (*hexutil.Big)(b.ChainConfig().ChainID)
args.ChainID = id
// If chain id is provided, ensure it matches the local chain id. Otherwise, set the local
// chain id as the default.
want := b.ChainConfig().ChainID
if args.ChainID != nil {
if have := (*big.Int)(args.ChainID); have.Cmp(want) != 0 {
return fmt.Errorf("chainId does not match node's (have=%v, want=%v)", have, want)
}
} else {
args.ChainID = (*hexutil.Big)(want)
}
return nil
}
Expand Down

0 comments on commit ecad8d6

Please sign in to comment.