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

[wip] use header type from libevm #746

Draft
wants to merge 10 commits into
base: libevm
Choose a base branch
from
Draft

Conversation

darioush
Copy link
Collaborator

No description provided.

@darioush darioush changed the base branch from master to libevm January 13, 2025 23:14

// HeaderSerializable defines the header of a block in the Ethereum blockchain,
// as it is to be serialized into RLP and JSON.
type HeaderSerializable struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible to unexport this type? 🤔

@@ -168,12 +168,13 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
}

// Verify BlockGasCost, ExtDataGasUsed not present before AP4
headerExtra := types.HeaderExtras(header)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we rename types.HeaderExtras to types.GetHeaderExtra? I don't like Get prefixes, but I prefer it compared to having the plural of extras despite accessing a single extra (and can't name it HeaderExtra due to type name conflict)

return nil
}

//nolint:stdmethods
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is ineffective, the warning comes from gopls AfAIK and no way to disable it unfortunately (again, AFAIK)

return out.MarshalJSON()
}

//nolint:stdmethods
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is ineffective, the warning comes from gopls AfAIK and no way to disable it unfortunately (again, AFAIK)

ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"`
}

// field type overrides for gencodec
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit it would be great to expand on the comment since this has a sort of special role and may be thought of as unneeded by a developer

Comment on lines +139 to +140
// updateFromEth updates the HeaderSerializable from the ethtypes.Header
func updateFromEth(h *HeaderSerializable, eth *ethtypes.Header) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this and the next few methods should be methods on the headerSerializable struct, so they don't name-conflict with future other types such as blockSerializable

Comment on lines +52 to +62
BloomLookup = ethtypes.BloomLookup
BytesToBloom = ethtypes.BytesToBloom
CreateBloom = ethtypes.CreateBloom
NewReceipt = ethtypes.NewReceipt
NewContractCreation = ethtypes.NewContractCreation
NewTransaction = ethtypes.NewTransaction
EncodeNonce = ethtypes.EncodeNonce
NewEmptyStateAccount = ethtypes.NewEmptyStateAccount
SlimAccountRLP = ethtypes.SlimAccountRLP
FullAccount = ethtypes.FullAccount
FullAccountRLP = ethtypes.FullAccountRLP
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might want to sort these (and existing ones too) alphabetically to have a consistent order with subnet-evm as well.

return extras.Header.Get(h)
}

func WithHeaderExtras(h *Header, extra *HeaderExtra) *Header {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to WithHeaderExtra?


// HeaderExtra is a struct that contains extra fields used by Avalanche
// in the block header.
// This type uses HeaderSerializable to encode and decode the extra fields
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit for godoc automated links

Suggested change
// This type uses HeaderSerializable to encode and decode the extra fields
// This type uses [HeaderSerializable] to encode and decode the extra fields

Comment on lines +132 to +134
extras.Header.Set(&cpy, &HeaderExtra{})
cpyExtra := HeaderExtras(&cpy)
*cpyExtra = *HeaderExtras(h)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit a bit less convoluted I think:

Suggested change
extras.Header.Set(&cpy, &HeaderExtra{})
cpyExtra := HeaderExtras(&cpy)
*cpyExtra = *HeaderExtras(h)
extra := HeaderExtras(h)
cpyExtra := &HeaderExtra{
ExtDataHash: extra.ExtDataHash,
}
cpy = *WithHeaderExtras(&cpy, cpyExtra)

You could also define hExtra instead of extra here to save one line below

Comment on lines +2182 to +2186
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/[email protected]", "-replace", "github.com/ava-labs/libevm=github.com/ava-labs/[email protected]")
replacer.Dir = pkg
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

A comment would be nice 😄
Maybe we can leave this commented with a comment explaining what it does for future work, before this gets merged / new libevm release.

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.

2 participants