Skip to content

Commit ecad8d6

Browse files
lightclientkaralabe
authored andcommittedOct 7, 2022
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 6f93ff9 commit ecad8d6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
 

‎internal/ethapi/transaction_args.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,15 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
165165
args.Gas = &estimated
166166
log.Trace("Estimate gas usage automatically", "gas", args.Gas)
167167
}
168-
if args.ChainID == nil {
169-
id := (*hexutil.Big)(b.ChainConfig().ChainID)
170-
args.ChainID = id
168+
// If chain id is provided, ensure it matches the local chain id. Otherwise, set the local
169+
// chain id as the default.
170+
want := b.ChainConfig().ChainID
171+
if args.ChainID != nil {
172+
if have := (*big.Int)(args.ChainID); have.Cmp(want) != 0 {
173+
return fmt.Errorf("chainId does not match node's (have=%v, want=%v)", have, want)
174+
}
175+
} else {
176+
args.ChainID = (*hexutil.Big)(want)
171177
}
172178
return nil
173179
}

0 commit comments

Comments
 (0)
Please sign in to comment.