go-ethereum icon indicating copy to clipboard operation
go-ethereum copied to clipboard

core/types: remove Message

Open roberto-bayardo opened this issue 2 years ago • 7 comments

This is a simple cleanup PR, the goal of which is to encapsulate all the Message related structures & abstractions within a single package (core). Previously it was leaking into core/types/Transaction.go, most of whose users have no need for it.

I've also changed Message to be a simple struct rather than a struct + an interface, as the interface was only adding unnecessary complexity.

roberto-bayardo avatar Oct 13 '22 01:10 roberto-bayardo

I like this, but would prefer not to have the NewMessage constructor. We will for sure have to add/change parameters of this function in the future. If they are passed by position, it can create a lot of extra changes.

fjl avatar Oct 13 '22 09:10 fjl

I like this, but would prefer not to have the NewMessage constructor. We will for sure have to add/change parameters of this function in the future. If they are passed by position, it can create a lot of extra changes.

I agree, there's no point of the constructor other than the fact that the members are currently not exported. In the interest of keeping this change contained, this might best be done in a second PR that also adresses the TODO I have there about removing the accessors and making it a purely data-only struct. (I'm happy to take that on next. and P.S.: This cleanup is in fact motivated by the challenges we faced adding in the maxFeePerDataGas field for EIP-4844!)

roberto-bayardo avatar Oct 13 '22 14:10 roberto-bayardo

@fjl here's how the followup PR which removes NewMessage and exports the struct members would look: https://github.com/roberto-bayardo/go-ethereum/pull/1

roberto-bayardo avatar Oct 14 '22 20:10 roberto-bayardo

Sorry, I will get to re-reviewing this PR soon!

fjl avatar Nov 30 '22 13:11 fjl

@fjl wdyt?

roberto-bayardo avatar Jan 19 '23 23:01 roberto-bayardo

I looked into your draft PR to remove the accessor methods, and we should get those changes in here as well.

fjl avatar Jan 31 '23 13:01 fjl

I looked into your draft PR to remove the accessor methods, and we should get those changes in here as well.

done

roberto-bayardo avatar Jan 31 '23 23:01 roberto-bayardo

I've rebased this, and have done some more renames.

fjl avatar Mar 08 '23 18:03 fjl

I've rebased this, and have done some more renames.

lgtm

roberto-bayardo avatar Mar 09 '23 01:03 roberto-bayardo

It's in! I added a bit of historical context to the commit message.

Here, the core.Message interface turns into a plain struct.

This is a breaking change to packages core and core/types. While we do not promise API stability for package core, we do for core/types. An exception can be made for types.Message, since it doesn't have any purpose apart from invoking the state transition in package core. types.Message was also marked deprecated in the same commit it got added, 4dca5d4db7 (November 2016).

The core.Message interface was added in December 2014, in commit db494170dc, for the purpose of 'testing' state transitions. It's the same commit that made transaction struct fields private. Before that change, the state transition was always invoked on full transactions.

Over time, multiple implementations of the interface accrued across different packages, since constructing a Message is required whenever one wants to invoke the state transition. These implementations all looked very similar, a struct with private fields exposing the fields as accessor methods.

By changing Message into a struct with public fields we can remove all these useless interface implementations. It will also hopefully simplify future changes to the type with less updates to apply across all of go-ethereum when a field is added to Message.

fjl avatar Mar 09 '23 13:03 fjl