From 2b956536e0f4045246ca5c9a5a4bde4b95f9ae3c Mon Sep 17 00:00:00 2001 From: Hussam Date: Mon, 7 Oct 2024 16:17:55 -0500 Subject: [PATCH 1/2] Return MixedCaseAddresses in RPC AccessLists --- core/types/transaction.go | 16 ++++++++++++++++ internal/quaiapi/api.go | 8 ++++---- internal/quaiapi/quai_api.go | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index 7a67a04ac..9480e232e 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -1234,12 +1234,20 @@ func (m *Message) SetData(data []byte) { // AccessList is an access list. type AccessList []AccessTuple +// MixedAccessList is an access list of MixedCaseAddresses +type MixedAccessList []MixedAccessTuple + // AccessTuple is the element type of an access list. type AccessTuple struct { Address common.Address `json:"address" gencodec:"required"` StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"` } +type MixedAccessTuple struct { + Address common.MixedcaseAddress `json:"address" gencodec:"required"` + StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"` +} + // StorageKeys returns the total number of storage keys in the access list. func (al AccessList) StorageKeys() int { sum := 0 @@ -1279,6 +1287,14 @@ func (al *AccessList) ProtoDecode(protoAccessList *ProtoAccessList, location com return nil } +func (al *AccessList) ConvertToMixedCase() *MixedAccessList { + MixedAccessList := make(MixedAccessList, 0, len(*al)) + for _, tup := range *al { + MixedAccessList = append(MixedAccessList, MixedAccessTuple{tup.Address.MixedcaseAddress(), tup.StorageKeys}) + } + return &MixedAccessList +} + // This function must only be used by tests func GetInnerForTesting(tx *Transaction) TxData { return tx.inner diff --git a/internal/quaiapi/api.go b/internal/quaiapi/api.go index 182b2cf95..185269ccb 100644 --- a/internal/quaiapi/api.go +++ b/internal/quaiapi/api.go @@ -1156,9 +1156,9 @@ func newRPCTransactionFromBlockHash(b *types.WorkObject, hash common.Hash, etxs // Its the result of the `debug_createAccessList` RPC call. // It contains an error if the transaction itself failed. type accessListResult struct { - Accesslist *types.AccessList `json:"accessList"` - Error string `json:"error,omitempty"` - GasUsed hexutil.Uint64 `json:"gasUsed"` + Accesslist *types.MixedAccessList `json:"accessList"` + Error string `json:"error,omitempty"` + GasUsed hexutil.Uint64 `json:"gasUsed"` } // CreateAccessList creates an AccessList for the given transaction. @@ -1179,7 +1179,7 @@ func (s *PublicBlockChainAPI) CreateAccessList(ctx context.Context, args Transac if err != nil { return nil, err } - result := &accessListResult{Accesslist: &acl, GasUsed: hexutil.Uint64(gasUsed)} + result := &accessListResult{Accesslist: acl.ConvertToMixedCase(), GasUsed: hexutil.Uint64(gasUsed)} if vmerr != nil { result.Error = vmerr.Error() } diff --git a/internal/quaiapi/quai_api.go b/internal/quaiapi/quai_api.go index 4adbabbf3..cac513835 100644 --- a/internal/quaiapi/quai_api.go +++ b/internal/quaiapi/quai_api.go @@ -625,7 +625,7 @@ func (s *PublicBlockChainQuaiAPI) CreateAccessList(ctx context.Context, args Tra if err != nil { return nil, err } - result := &accessListResult{Accesslist: &acl, GasUsed: hexutil.Uint64(gasUsed)} + result := &accessListResult{Accesslist: acl.ConvertToMixedCase(), GasUsed: hexutil.Uint64(gasUsed)} if vmerr != nil { result.Error = vmerr.Error() } From 1df3a05665951b48999eeedff61559ae3db7d458 Mon Sep 17 00:00:00 2001 From: Hussam Date: Mon, 7 Oct 2024 16:51:04 -0500 Subject: [PATCH 2/2] Fix tx receipt crash for contracts --- internal/quaiapi/api.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/quaiapi/api.go b/internal/quaiapi/api.go index 185269ccb..f67fe98f1 100644 --- a/internal/quaiapi/api.go +++ b/internal/quaiapi/api.go @@ -1436,7 +1436,6 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha "transactionHash": hash, "transactionIndex": hexutil.Uint64(index), "from": from.Hex(), - "to": tx.To().Hex(), "gasUsed": hexutil.Uint64(receipt.GasUsed), "cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed), "contractAddress": nil, @@ -1445,6 +1444,10 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha "type": hexutil.Uint(tx.Type()), } + if to := tx.To(); to != nil { + fields["to"] = to.Hex() + } + if tx.Type() == types.ExternalTxType { fields["originatingTxHash"] = tx.OriginatingTxHash() fields["etxType"] = hexutil.Uint(tx.EtxType())