go-ethereum
go-ethereum copied to clipboard
core/types: remove Message
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.
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 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!)
@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
Sorry, I will get to re-reviewing this PR soon!
@fjl wdyt?
I looked into your draft PR to remove the accessor methods, and we should get those changes in here as well.
I looked into your draft PR to remove the accessor methods, and we should get those changes in here as well.
done
I've rebased this, and have done some more renames.
I've rebased this, and have done some more renames.
lgtm
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.