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 libevm (params, core/vm) #1335

Draft
wants to merge 49 commits into
base: master
Choose a base branch
from
Draft

wip: use libevm (params, core/vm) #1335

wants to merge 49 commits into from

Conversation

darioush
Copy link
Collaborator

@darioush darioush commented Sep 5, 2024

initial attempt to use libevm params extensions

@darioush darioush force-pushed the use-libevm-params branch 2 times, most recently from 95ce588 to 8574ab3 Compare September 10, 2024 16:16
@darioush darioush changed the title wip: use libevm (params) wip: use libevm (params, core/vm) Sep 12, 2024

// Durango enables the Shanghai upgrade of eth, which takes place after the
// Merge upgrade.
isDurango := params.GetExtra(chain.Config()).IsDurango(header.Time)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

upstream avoids this dependency here (on chain config/rules) by checking if Difficulty is 0,
but we cannot rely on that because we already made blocks with difficulty set to 1.

chainConfig *gethparams.ChainConfig
blockContext *BlockContext
}

func (a accessableState) GetStateDB() contract.StateDB {
// XXX: Whoa, this is a hack
return a.StateDB.(contract.StateDB)
return a.StateReader.(contract.StateDB)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just to make it compliant with an existing interface?

To guarantee that it's safe, without using the , ok idiom you could:

var (
    sr libevm.StateReader = a.StateReader
    _ contract.StateDB = (libevm.StateReader)(nil) // prove that the next line won't panic
)
return sr.(contract.StateDB)

It's gross, but at least it's temporary!

@@ -695,6 +695,11 @@ func TestPrecompileBind(t *testing.T) {
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/[email protected]", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/[email protected]")
Copy link
Collaborator

Choose a reason for hiding this comment

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

any reason why we not directly use ava-labs/go-ethereum as directy dependency?

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 module renaming is not ready yet, we will use it directly once it is ready.

@@ -205,7 +205,7 @@ func Transition(ctx *cli.Context) error {

func applyLondonChecks(env *stEnv, chainConfig *params.ChainConfig) error {
// NOTE: IsLondon replaced with IsSubnetEVM here
if !chainConfig.IsSubnetEVM(env.Timestamp) {
if !params.GetExtra(chainConfig).IsSubnetEVM(env.Timestamp) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should just use London here

@@ -80,7 +80,7 @@ func ReadChainConfig(db ethdb.KeyValueReader, hash common.Hash) *params.ChainCon
if len(data) == 0 {
return &config // return early if no upgrade config is found
}
if err := json.Unmarshal(data, &config.UpgradeConfig); err != nil {
if err := json.Unmarshal(data, &params.GetExtra(&config).UpgradeConfig); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: should we instead treat UpgradeConfig as a seperate struct and then set to configExtra? I assume config.UpgradeConfig initially should be empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do you mean handling it entirely separately? I tried something like this here: #1351

@@ -75,17 +75,17 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
return fmt.Errorf("%w: transaction size %v, limit %v", ErrOversizedData, tx.Size(), opts.MaxSize)
}
// Ensure only transactions that have been enabled are accepted
if !opts.Config.IsSubnetEVM(head.Time) && tx.Type() != types.LegacyTxType {
if !params.GetExtra(opts.Config).IsSubnetEVM(head.Time) && tx.Type() != types.LegacyTxType {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we rather use equivalent geth forks like london here?

}
return sum
}
type AccessTuple = gethtypes.AccessTuple

// AccessListTx is the data of EIP-2930 access list transactions.
type AccessListTx struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we keep this as a seperate struct here?

}

func (r *Rules) PredicatersExist() bool {
func (r *RulesExtra) PredicatersExist() bool {
// Methods on *RulesExtra handle nil receiver so params.Rules is an initialized struct.
Copy link
Collaborator

Choose a reason for hiding this comment

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

in what case we call function on a nil pointer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it is needed, removed it for now

Comment on lines +328 to +339
func WithExtra(c *ChainConfig, extra *ChainConfigExtra) *ChainConfig {
// XXX: Hack to initialize the ChainConfigExtra pointer in the ChainConfig.
jsonBytes, err := json.Marshal(c)
if err != nil {
panic(err)
}
var newCfg ChainConfig
if err := json.Unmarshal(jsonBytes, &newCfg); err != nil {
panic(err)
}

*GetExtra(&newCfg) = *extra
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit lost here. Why do we need to do marshal+unmarshaling? Also that setting double pointer with GetExtra seems too hacky. can we rather have a setter in libevm if we cannot initialize chainconfig without this? Maybe the whole WithExtra thing can be moved to libevm?

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 marshal / unmarshal is no longer needed and we can use the SetOnChainConfig method here.

blockContext: &BlockContext{
number: env.BlockNumber(),
time: env.BlockTime(),
predicateResults: predicateResults,
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems we have removed predicateResults from vm.BlockContext (in core), should we rather pass them with header.extra and let the consumer parse it?

Comment on lines +23 to +24
var PredicateParser = func(extra []byte) (PredicateResults, error) {
return nil, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's a bit hard to follow this and weird to expect some other pkg to set this to the actual implementation.

@@ -27,7 +27,7 @@ func NewBlockValidator() BlockValidator {
return &blockValidator{}
}

func (v blockValidator) SyntacticVerify(b *Block, rules params.Rules) error {
func (v blockValidator) SyntacticVerify(b *Block, rules_ params.Rules) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can we rename rules_ to rules and then below rules to rulesExtra?

Copy link
Collaborator

@ceyonur ceyonur left a comment

Choose a reason for hiding this comment

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

can we also use this or create another as a base branch for libevm work? IMHO we should test these as a whole before merging to master. We can even constantly run a node with the libevm base branch.

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