internal/ethapi: error if tx args includes chain id that doesn't match local (#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 <peterke@gmail.com>
This commit is contained in:
lightclient 2022-07-14 04:17:25 -06:00 committed by GitHub
parent b53d38246e
commit 434ca026c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -165,9 +165,15 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
args.Gas = &estimated args.Gas = &estimated
log.Trace("Estimate gas usage automatically", "gas", args.Gas) log.Trace("Estimate gas usage automatically", "gas", args.Gas)
} }
if args.ChainID == nil { // If chain id is provided, ensure it matches the local chain id. Otherwise, set the local
id := (*hexutil.Big)(b.ChainConfig().ChainID) // chain id as the default.
args.ChainID = id 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 return nil
} }