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

fix(rawdb, api): fix rawdb.writeSkippedTransaction & api.GetSkippedTransaction #503

Merged
merged 4 commits into from
Sep 7, 2023

Conversation

0xmountaintop
Copy link

@0xmountaintop 0xmountaintop commented Sep 6, 2023

1. Purpose or design rationale of this PR

Error

$ curl --location --request POST 'http://localhost:8545' --header 'Content-Type: application/json' --data-raw '{"jsonrpc": "2.0","method": "scroll_getSkippedTransaction","params":["0x734c3a3aeb0a1b993b9b3b8f55200c413251cdd2fd71ff8edd3b544da592e228"],"id": 1}'
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"fail to Unmarshal traces for skipped tx, hash: 0x734c3a3aeb0a1b993b9b3b8f55200c413251cdd2fd71ff8edd3b544da592e228, err: json: Unmarshal(nil *types.BlockTrace)"}}

Summary:

  • no need to marshal if traces is nil
  • when doing Unmarshal, must use a nil-pointer for the receiver

You can verify using this PoC:

type RPCTransaction struct {
	Traces *types.BlockTrace `json:"traces,omitempty"`
}

func main() {
	tracesBytes, err := json.Marshal(nil)
	if err != nil {
		panic(err) 
	}

	var rpcTx RPCTransaction
	if len(tracesBytes) != 0 {
		if err := json.Unmarshal(tracesBytes, rpcTx.Traces); err != nil {
			fmt.Printf("fail to Unmarshal traces for skipped tx1, err: %v\n", err)
		}
		traces:= &types.BlockTrace{}
		if err := json.Unmarshal(tracesBytes, traces); err != nil {
			fmt.Printf("fail to Unmarshal traces for skipped tx 2, err: %v\n", err)
		}
	}

	var xxx *types.BlockTrace
	tracesBytes, err = json.Marshal(xxx)
	if err != nil {
		panic(err) 
	}

	if len(tracesBytes) != 0 {
		if err := json.Unmarshal(tracesBytes, rpcTx.Traces); err != nil {
			fmt.Printf("fail to Unmarshal traces for skipped tx 3, err: %v\n", err)
		}
	}
}

Have tested this PR locally.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • build: Changes that affect the build system or external dependencies (example scopes: yarn, eslint, typescript)
  • ci: Changes to our CI configuration files and scripts (example scopes: vercel, github, cypress)
  • docs: Documentation-only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

@0xmountaintop 0xmountaintop changed the title fix(rawsdb): fix writeSkippedTransaction fix(rawdb): fix writeSkippedTransaction Sep 6, 2023
miner/worker.go Outdated Show resolved Hide resolved
@0xmountaintop 0xmountaintop marked this pull request as draft September 7, 2023 06:34
@0xmountaintop 0xmountaintop changed the title fix(rawdb): fix writeSkippedTransaction [WIP] fix(rawdb): fix writeSkippedTransaction Sep 7, 2023
@0xmountaintop 0xmountaintop changed the title [WIP] fix(rawdb): fix writeSkippedTransaction [WIP] fix(rawdb, api): fix rawdb.writeSkippedTransaction & api.GetSkippedTransaction Sep 7, 2023
@0xmountaintop 0xmountaintop changed the title [WIP] fix(rawdb, api): fix rawdb.writeSkippedTransaction & api.GetSkippedTransaction fix(rawdb, api): fix rawdb.writeSkippedTransaction & api.GetSkippedTransaction Sep 7, 2023
@0xmountaintop 0xmountaintop marked this pull request as ready for review September 7, 2023 07:10
@0xmountaintop 0xmountaintop merged commit dade96d into develop Sep 7, 2023
10 checks passed
@0xmountaintop 0xmountaintop deleted the fix/store_traces branch September 7, 2023 07:35
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