relab / hotstuff

MIT License
167 stars 53 forks source link

Command semantics verification as part of block verification? #27

Closed raphjaph closed 3 years ago

raphjaph commented 3 years ago

I'm not quite sure if this is the correct place to ask but I was wondering where in consensus.go would be the best place to verify the commands in a block. As I understand it, the OnReceiveProposal() function just checks the block is placed correctly in the chain but it doesn't look inside the blocks to check the semantics of the commands. My idea was to just place the check at the beginning of that function (as seen below). Is this the right way/place to perform such checks?

// OnReceiveProposal handles a replica's response to the Proposal from the leader
func (hs *HotStuffCore) OnReceiveProposal(block *data.Block) (*data.PartialCert, error) {
    logger.Println("OnReceiveProposal:", block)
    hs.Blocks.Put(block)

    // checks if all commands in a block conform to a specific rule set
    if hs.invalidCommandsInBlock(block) {
        fmt.Println("Proposed block contains invalid command")
        return nil, fmt.Errorf("Invalid command")
    }

Thanks!

johningve commented 3 years ago

We recently added an Acceptor interface that you can implement in order to verify the commands. We call the Accept() method on this interface after a block has been determined to be safe. See the code here. In your case it should be fine to check the commands at the beginning of the function like you suggested.

raphjaph commented 3 years ago

Great, thanks for the prompt answer! Seems like I still had the repo state from last month. Will have a look at all the refactoring.