-
Notifications
You must be signed in to change notification settings - Fork 20.5k
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
signer: implement blob txs sendtxargs, enable blobtx-signing #28976
Changes from 1 commit
da67944
43f29d5
91fa8df
a39e697
1fd10ad
75f03ce
8a35841
bcd9790
9c2bb33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ import ( | |
"github.com/ethereum/go-ethereum/common/math" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/crypto/kzg4844" | ||
"github.com/holiman/uint256" | ||
) | ||
|
||
var typedDataReferenceTypeRegexp = regexp.MustCompile(`^[A-Za-z](\w*)(\[\])?$`) | ||
|
@@ -92,12 +94,21 @@ type SendTxArgs struct { | |
// We accept "data" and "input" for backwards-compatibility reasons. | ||
// "input" is the newer name and should be preferred by clients. | ||
// Issue detail: https://github.com/ethereum/go-ethereum/issues/15628 | ||
Data *hexutil.Bytes `json:"data"` | ||
Data *hexutil.Bytes `json:"data,omitempty"` | ||
Input *hexutil.Bytes `json:"input,omitempty"` | ||
|
||
// For non-legacy transactions | ||
AccessList *types.AccessList `json:"accessList,omitempty"` | ||
ChainID *hexutil.Big `json:"chainId,omitempty"` | ||
|
||
// For BlobTxType | ||
BlobFeeCap *hexutil.Big `json:"maxFeePerBlobGas,omitempty"` | ||
BlobHashes []common.Hash `json:"blobVersionedHashes,omitempty"` | ||
|
||
// For BlobTxType transactions with blob sidecar | ||
Blobs []kzg4844.Blob `json:"blobs,omitempty"` | ||
Commitments []kzg4844.Commitment `json:"commitments,omitempty"` | ||
Proofs []kzg4844.Proof `json:"proofs,omitempty"` | ||
} | ||
|
||
func (args SendTxArgs) String() string { | ||
|
@@ -108,6 +119,17 @@ func (args SendTxArgs) String() string { | |
return err.Error() | ||
} | ||
|
||
// data retrieves the transaction calldata. Input field is preferred. | ||
func (args *SendTxArgs) data() []byte { | ||
if args.Input != nil { | ||
return *args.Input | ||
} | ||
if args.Data != nil { | ||
return *args.Data | ||
} | ||
return nil | ||
} | ||
|
||
// ToTransaction converts the arguments to a transaction. | ||
func (args *SendTxArgs) ToTransaction() *types.Transaction { | ||
// Add the To-field, if specified | ||
|
@@ -117,15 +139,34 @@ func (args *SendTxArgs) ToTransaction() *types.Transaction { | |
to = &dstAddr | ||
} | ||
|
||
var input []byte | ||
if args.Input != nil { | ||
input = *args.Input | ||
} else if args.Data != nil { | ||
input = *args.Data | ||
} | ||
|
||
var data types.TxData | ||
switch { | ||
case args.BlobHashes != nil: | ||
al := types.AccessList{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will always add an empty access list? Could be simpler by assigning to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, wait, so the issue is actually that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I just copy-pasted this from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, so maybe it's wrong there too. |
||
if args.AccessList != nil { | ||
al = *args.AccessList | ||
} | ||
data = &types.BlobTx{ | ||
To: *to, | ||
ChainID: uint256.MustFromBig((*big.Int)(args.ChainID)), | ||
Nonce: uint64(args.Nonce), | ||
Gas: uint64(args.Gas), | ||
GasFeeCap: uint256.MustFromBig((*big.Int)(args.MaxFeePerGas)), | ||
GasTipCap: uint256.MustFromBig((*big.Int)(args.MaxPriorityFeePerGas)), | ||
Value: uint256.MustFromBig((*big.Int)(&args.Value)), | ||
Data: args.data(), | ||
AccessList: al, | ||
BlobHashes: args.BlobHashes, | ||
BlobFeeCap: uint256.MustFromBig((*big.Int)(args.BlobFeeCap)), | ||
} | ||
if args.Blobs != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this needs to be changed to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is done in |
||
data.(*types.BlobTx).Sidecar = &types.BlobTxSidecar{ | ||
Blobs: args.Blobs, | ||
Commitments: args.Commitments, | ||
Proofs: args.Proofs, | ||
} | ||
} | ||
|
||
case args.MaxFeePerGas != nil: | ||
al := types.AccessList{} | ||
if args.AccessList != nil { | ||
|
@@ -139,7 +180,7 @@ func (args *SendTxArgs) ToTransaction() *types.Transaction { | |
GasFeeCap: (*big.Int)(args.MaxFeePerGas), | ||
GasTipCap: (*big.Int)(args.MaxPriorityFeePerGas), | ||
Value: (*big.Int)(&args.Value), | ||
Data: input, | ||
Data: args.data(), | ||
AccessList: al, | ||
} | ||
case args.AccessList != nil: | ||
|
@@ -150,7 +191,7 @@ func (args *SendTxArgs) ToTransaction() *types.Transaction { | |
Gas: uint64(args.Gas), | ||
GasPrice: (*big.Int)(args.GasPrice), | ||
Value: (*big.Int)(&args.Value), | ||
Data: input, | ||
Data: args.data(), | ||
AccessList: *args.AccessList, | ||
} | ||
default: | ||
|
@@ -160,7 +201,7 @@ func (args *SendTxArgs) ToTransaction() *types.Transaction { | |
Gas: uint64(args.Gas), | ||
GasPrice: (*big.Int)(args.GasPrice), | ||
Value: (*big.Int)(&args.Value), | ||
Data: input, | ||
Data: args.data(), | ||
} | ||
} | ||
return types.NewTx(data) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this is annoying. Can we keep this check somehow if the signer is not "external"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the vein of deprecating Sign/SendTransaction methods I think we shouldn't add new features (i.e. here blob txes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right. So, on personal, I think we can leave this be. That is: my change here can be undone