Skip to content

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

Merged
merged 43 commits into from
Apr 16, 2021

Conversation

gballet
Copy link
Member

@gballet gballet commented Apr 9, 2021

Remove all the superfluous code from #22468 to prepare for rayonism:

  • Remove RANDAOMIX and BEACONSTATEROOT instructions
  • Rename API calls and change inputs

@gballet gballet force-pushed the catalyst-for-rayonism branch from 19fe89f to 26ee92a Compare April 9, 2021 13:15
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 {
Copy link
Member

@rjl493456442 rjl493456442 Apr 13, 2021

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)
Copy link
Member

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()
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member 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 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
Copy link
Member

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?

Copy link
Member

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"`
}
Copy link
Member

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?

Copy link
Contributor

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

Copy link
Contributor

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
Comment on lines 310 to 325
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
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this needed?

Copy link
Member Author

@gballet gballet Apr 14, 2021

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",
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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"`
}
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

@@ -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) {
Copy link
Contributor

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))
Copy link
Member Author

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 {
Copy link
Contributor

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
Comment on lines 312 to 324
//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
Copy link
Contributor

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?

@fjl fjl changed the title eth/catalyst: add catalyst prototype for rayonism eth/catalyst: add catalyst API prototype Apr 16, 2021
@fjl fjl added this to the 1.10.3 milestone Apr 16, 2021
fjl added 7 commits April 16, 2021 19:31
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.
@fjl fjl merged commit f79cce5 into ethereum:master Apr 16, 2021
atif-konasl pushed a commit to frozeman/pandora-execution-engine that referenced this pull request Oct 15, 2021
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>
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.

6 participants