Skip to content

Commit 734c819

Browse files
lightclientkaralabe
authored andcommitted
internal/ethapi: error if tx args includes chain id that doesn't match 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 <peterke@gmail.com>
1 parent b90c634 commit 734c819

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

internal/ethapi/transaction_args.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,15 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
172172
args.Gas = &estimated
173173
log.Trace("Estimate gas usage automatically", "gas", args.Gas)
174174
}
175-
if args.ChainID == nil {
176-
id := (*hexutil.Big)(b.ChainConfig().ChainID)
177-
args.ChainID = id
175+
// If chain id is provided, ensure it matches the local chain id. Otherwise, set the local
176+
// chain id as the default.
177+
want := b.ChainConfig().ChainID
178+
if args.ChainID != nil {
179+
if have := (*big.Int)(args.ChainID); have.Cmp(want) != 0 {
180+
return fmt.Errorf("chainId does not match node's (have=%v, want=%v)", have, want)
181+
}
182+
} else {
183+
args.ChainID = (*hexutil.Big)(want)
178184
}
179185
return nil
180186
}

0 commit comments

Comments
 (0)