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

Align RPC with geth #1841

Merged
merged 8 commits into from
Mar 20, 2024
Merged

Align RPC with geth #1841

merged 8 commits into from
Mar 20, 2024

Conversation

tudor-malene
Copy link
Collaborator

@tudor-malene tudor-malene commented Mar 19, 2024

Why this change is needed

  • align some RPC methods with the expected geth results
  • in preparation for a more rigorous OG RPC

What changes were made as part of this PR

  • remove the custom "nil response" method and align with geth. Also adjust the "Await transaction" logic (which should be consolidated)
  • use the block or hash type
  • change the receipt response
  • change the transaction response
  • adjust the input parameters

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

@@ -145,33 +144,68 @@ func ExtractAddress(param interface{}) (*gethcommon.Address, error) {
}

// ExtractOptionalBlockNumber defaults nil or empty block number params to latest block number
func ExtractOptionalBlockNumber(params []interface{}, idx int) (*gethrpc.BlockNumber, error) {
func ExtractOptionalBlockNumber(params []interface{}, idx int) (*gethrpc.BlockNumberOrHash, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the geth api can send either a block number or a hash.
We currently only support the former, but this change creates the plumbing for both

@@ -13,7 +17,7 @@ import (
"github.com/ten-protocol/go-ten/go/enclave/events"
)

func GetTransactionReceiptValidate(reqParams []any, builder *CallBuilder[gethcommon.Hash, types.Receipt], _ *EncryptionManager) error {
func GetTransactionReceiptValidate(reqParams []any, builder *CallBuilder[gethcommon.Hash, map[string]interface{}], _ *EncryptionManager) error {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the geth api actually returns a map when you ask for receipts.

@@ -2,6 +2,8 @@ package obsclient

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes in this file are aligning with geth

@@ -235,7 +225,7 @@ func (c *EncRPCClient) executeSensitiveCall(ctx context.Context, result interfac

// If there is no encrypted response then this is equivalent to nil response
if rawResult.EncUserResponse == nil || len(rawResult.EncUserResponse) == 0 {
return ErrNilResponse
return nil
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that error has no equivalent in geth

Copy link
Contributor

@zkokelj zkokelj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 , 2 minor comments added

@@ -47,7 +47,8 @@ func EstimateGasValidate(reqParams []any, builder *CallBuilder[CallParamsWithBlo
}

builder.From = callMsg.From
builder.Param = &CallParamsWithBlock{callMsg, blockNumber}
// todo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: What needs to be done here or can be this todo removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to support retrieval by hash. Currently it only works by height

@@ -56,7 +56,7 @@ func GetTransactionExecute(builder *CallBuilder[gethcommon.Hash, RpcTransaction]
// Unlike in the Geth impl, we hardcode the use of a London signer.
// todo (#1553) - once the enclave's genesis.json is set, retrieve the signer type using `types.MakeSigner`
signer := types.NewLondonSigner(tx.ChainId())
rpcTx := newRPCTransaction(tx, blockHash, blockNumber, index, gethcommon.Big0, signer)
rpcTx := newRPCTransaction(tx, blockHash, blockNumber, index, rpc.config.BaseFee, signer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity.. do we want to have it configurable? Before it was hardcoded to 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently we have a static configured base fee.
Eventually, it needs to be dynamic.
The problem here was that this was returning 0

Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me so long as tests are all behaving. One minor thing I think needs fixing.

@@ -85,7 +83,7 @@ func (f *Faucet) validateTx(tx *types.Transaction) error {
for now := time.Now(); time.Since(now) < _timeout; time.Sleep(time.Second) {
receipt, err := f.client.TransactionReceipt(context.Background(), tx.Hash())
if err != nil {
if errors.Is(err, rpc.ErrNilResponse) {
if receipt == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to check the type of error here is ethereum.NotFound I think? Else it'll keep waiting when the node is down for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good spot. this logic is dodgy here

@tudor-malene tudor-malene merged commit fdde1b7 into main Mar 20, 2024
2 checks passed
@tudor-malene tudor-malene deleted the tudor/rpc_fixes branch March 20, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants