Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,16 @@ 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)
// 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 {
got := (*big.Int)(args.ChainID)
if want.Cmp(got) != 0 {
return fmt.Errorf("chainId does not match local (got=%s, want=%s)", got.String(), want.String())
}
} else {
id := (*hexutil.Big)(want)
args.ChainID = id
}
return nil
Expand Down