-
Notifications
You must be signed in to change notification settings - Fork 20.8k
eth/catalyst: add catalyst API prototype #22641
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
Conversation
…ructions Co-Authored-By: Mikhail Kalinin <noblesse.knight@gmail.com>
19fe89f
to
26ee92a
Compare
eth/eth2.go
Outdated
return nil, fmt.Errorf("child timestamp lower than parent's: %d >= %d", parent.Time(), params.Timestamp) | ||
} | ||
// this will ensure we're not going off too far in the future | ||
if now := uint64(time.Now().Unix()); params.Timestamp > now+1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the sanity check is needed here. I image it's possible in the future that users put beacon node and geth node into two separate machines and connect them via RPC. So it's possible that the geth node machine is time delayed and return the block with long time sleeping(e.g. 5 second).
IIUC, in the eth2, the block has to be purposed in the given time limit. Maybe it would make more sense to do the sleeping in the eth2 part?
Just throw out the thoughts.
eth/eth2.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
signer := types.NewEIP155Signer(bc.Config().ChainID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use types.LatestSigner()
eth/eth2.go
Outdated
} | ||
|
||
func (api *Eth2API) commitTransaction(tx *types.Transaction, coinbase common.Address) error { | ||
//snap := eth2rpc.current.state.Snapshot() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason to remove this "snapshot" mechanism?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes: it didn't work and wasn't needed for the prototype
There was a problem hiding this comment.
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 makes sense to try activating it now, this part will be replaced with your PR soon enough.
eth/eth2.go
Outdated
// Update the block hash in all logs since it is now available and not when the | ||
// receipt/log of individual transactions were created. | ||
for _, log := range receipt.Logs { | ||
log.BlockHash = hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QQ: Looks like the log.BlockHash
is set to "application-layer" block hash. Do we have any spec for defining the expected behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the eth2 block hash is not available here. I guess the application layer block hash is the only option here.
eth/eth2.go
Outdated
Timestamp uint64 `json:"timestamp"` | ||
RecentBeaconBlockRoots []common.Hash `json:"recent_beacon_block_roots"` | ||
ExecutableData ExecutableData `json:"executable_data"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RandaoMix
, Slot
and RecentBeaconBlockRoots
seems unused. I guess they are removed from the spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are useful to have when implementing the opcodes (which were present in previous catalyst versions). It was indeed removed from the latest spec for simplicity of the first devnet.
You can find the latest spec for RPC here: https://notes.ethereum.org/@n0ble/rayonism-the-merge-spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, according to the spec there is also ExecutionPayload
object in the params of this method, https://notes.ethereum.org/@n0ble/rayonism-the-merge-spec#Parameters1
eth/eth2.go
Outdated
func (api *Eth2API) SetHead(newHead common.Hash) error { | ||
//oldBlock := api.eth.BlockChain().CurrentBlock() | ||
|
||
//if oldBlock.Hash() == newHead { | ||
//return nil | ||
//} | ||
|
||
//newBlock := api.eth.BlockChain().GetBlockByHash(newHead) | ||
|
||
//err := api.eth.BlockChain().Reorg(oldBlock, newBlock) | ||
//if err != nil { | ||
//return err | ||
//} | ||
//api.head = newHead | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a previous version of the spec, yes. But not anymore. I kept it in case people decide they need it after all. It will be replaced with a call to Gary's PR soon enough.In the mean time, it's just a placeholder.
eth/backend.go
Outdated
@@ -337,6 +342,11 @@ func (s *Ethereum) APIs() []rpc.API { | |||
Version: "1.0", | |||
Service: s.netRPCService, | |||
Public: true, | |||
}, { | |||
Namespace: "eth2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://notes.ethereum.org/@n0ble/rayonism-the-merge-spec
This was renamed to "consensus". @mkalinin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preference is to use consensus
name for this namespace. Should not be difficult to update, right?
eth/eth2.go
Outdated
BlockHash common.Hash `json:"block_hash"` | ||
ParentHash common.Hash `json:"parent_hash"` | ||
Difficulty *big.Int `json:"difficulty"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a slightly different field set for the ExecutionPayload
in the Rayonism spec. Please, take a look here https://notes.ethereum.org/@n0ble/rayonism-the-merge-spec#Parameters1.
eth/eth2.go
Outdated
block := insertBlockParamsToBlock(params, number) | ||
_, err := api.eth.BlockChain().InsertChainWithoutSealVerification(types.Blocks([]*types.Block{block})) | ||
|
||
return (err == nil), err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May a result object be returned here with valid
flag in it (https://notes.ethereum.org/@n0ble/rayonism-the-merge-spec#Returns1)? The idea is to make this object extensible to allow for adding additional info in return like the reason of block invalidity (might be useful for debugging).
eth/eth2.go
Outdated
//return err | ||
//} | ||
//api.head = newHead | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to adjust the result with the spec (https://notes.ethereum.org/@n0ble/rayonism-the-merge-spec#Return). The same is for FinalizeBlock
method.
core/blockchain.go
Outdated
@@ -1693,6 +1693,44 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { | |||
return n, err | |||
} | |||
|
|||
// InsertChainWithoutSealVerification works exactly the same | |||
// except for seal verification, seal verification is omitted | |||
func (bc *BlockChain) InsertChainWithoutSealVerification(chain types.Blocks) (int, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ever called with a slice containing one block, AFAICT. Might just make it take a single block on input, and throw away the whole sanity check loop
eth/eth2.go
Outdated
return &NewBlockReturn{false}, fmt.Errorf("could not find parent %x", params.ParentHash) | ||
} | ||
number := big.NewInt(0) | ||
number.Add(parent.Number(), big.NewInt(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't compute the number
eth/eth2.go
Outdated
return &Eth2API{eth: eth} | ||
} | ||
|
||
type eth2bpenv struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to something meaningful
eth/eth2.go
Outdated
//oldBlock := api.eth.BlockChain().CurrentBlock() | ||
|
||
//if oldBlock.Hash() == newHead { | ||
//return nil | ||
//} | ||
|
||
//newBlock := api.eth.BlockChain().GetBlockByHash(newHead) | ||
|
||
//err := api.eth.BlockChain().Reorg(oldBlock, newBlock) | ||
//if err != nil { | ||
//return err | ||
//} | ||
//api.head = newHead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps remove the dead commented code?
This makes the API object encoding adhere to the spec as written: all integers are hex string QUANTITY, all bytes data is hex string DATA, and transactions are hex strings instead of JSON objects.
types.LatestSigner is for code that doesn't know the block number. When creating the new block in catalyst, the number is known, and MakeSigner should be used.
This makes 'env' local to AssembleBlock instead of keeping it in the api object. Doing this avoids races for concurrent calls of AssembleBlock.
In receipts and logs, the block location fields are not part of consensus and don't need to be derived because they will be thrown away. Also remove pointless assignment of the ReceiptHash after this. Block.Header() returns a copy of the header, so modifying the receipt hash doesn't do anything.
This change adds the --catalyst flag, enabling an RPC API for eth2 integration. In this initial version, catalyst mode also disables all peer-to-peer networking. Co-authored-by: Mikhail Kalinin <noblesse.knight@gmail.com> Co-authored-by: Felix Lange <fjl@twurst.com>
Remove all the superfluous code from #22468 to prepare for rayonism:
RANDAOMIX
andBEACONSTATEROOT
instructions