Skip to content

core block height consensus - #3

Closed
QuantumExplorer wants to merge 2 commits into
dashpay:masterfrom
QuantumExplorer:quantumexplorer/coreChainLocksV2
Closed

QuantumExplorer wants to merge 2 commits into
dashpay:masterfrom
QuantumExplorer:quantumexplorer/coreChainLocksV2

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Description

This is the initial implementation of core chain locks in Tenderdash. Core chain locks add an external source of truth to the tendermint consensus and allow for Platform Data to reference Core Chain block heights.

@QuantumExplorer
QuantumExplorer marked this pull request as draft October 11, 2020 02:03
Comment thread abci/client/client.go
SetOptionAsync(types.RequestSetOption) *ReqRes
DeliverTxAsync(types.RequestDeliverTx) *ReqRes
CheckTxAsync(types.RequestCheckTx) *ReqRes
CheckQuorumSignatureAsync(types.RequestCheckQuorumSignature) *ReqRes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We agreed to use the existing query connection and query method.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

++

@QuantumExplorer QuantumExplorer Oct 21, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As I was going through the code, I just can't bring myself to use the query method, it just doesn't seem clean enough to me and I couldn't find a way to make it feel clean. I switched to query connection though. If anyone feels really strongly about this please just do a PR to this branch.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No problem. I'll do PR tomorrow.

@shumkov shumkov changed the title Core chain locks implementation core height consensus Oct 11, 2020
@shumkov shumkov changed the title core height consensus core block height consensus Oct 11, 2020
Comment thread types/validation.go Resolved
Comment thread types/proposal.go Resolved
Comment thread types/proposal.go
Signature []byte `json:"signature"`
Type tmproto.SignedMsgType
Height int64 `json:"height"`
CoreChainLockedHeight uint32 `json:"coreHeight"`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

coreChainLockedHeight?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For JSON I do not think we should have such a long string, it seems wasteful. However it should be snake_case I think.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm ok to keep it short. But you right, it must be a snake case.

BTW, I feel like it's better to add our fields to the end of structures so it will be easier to merge with upstream and see changes from our side. Any thoughts?

Comment thread types/params.go
func DefaultConsensusParams() *tmproto.ConsensusParams {
return &tmproto.ConsensusParams{
Block: DefaultBlockParams(),
ChainLock: DefaultChainLockParams(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We decided to move out ChainLock from ConsenusParams to just EndBlockResponse.

Comment thread types/genesis.go
AppState json.RawMessage `json:"app_state,omitempty"`
GenesisTime time.Time `json:"genesis_time"`
ChainID string `json:"chain_id"`
GenesisChainLock tmproto.ChainLock `json:"genesis_chain_lock"`

@shumkov shumkov Oct 12, 2020 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread types/event_bus_test.go
defer eventBus.Stop()

block := MakeBlock(0, []Tx{}, nil, []Evidence{})
block := MakeBlock(0, 0,nil, []Tx{}, nil, []Evidence{})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

formatting

Comment thread types/event_bus_test.go
defer eventBus.Stop()

block := MakeBlock(0, []Tx{}, nil, []Evidence{})
block := MakeBlock(0,0, nil, []Tx{}, nil, []Evidence{})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

formatting

Comment thread types/chainLock.go
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

type ChainLock struct {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CoreChainLock?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmmm, it's a chain lock, no need to say it's core.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are 2 chains, Tendermint and Core. Just to represent that's Core feature, not Tendermint. No?

Comment thread types/chainLock.go
)

type ChainLock struct {
CoreBlockHeight uint32 `json:"core_block_height,string,omitempty"` // height of Chain Lock.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

BlockHeigth?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are 2 block heights, one core and one platform, expressing which one I think makes this more easy to understand.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But it's a field in ChainLock structure, so it already namespaced by Core, right? It's like when you have an object core you don't name properties like core.coreBlockHeight, core.coreBestChainLock or something like this.

Comment thread types/chainLock.go

type ChainLock struct {
CoreBlockHeight uint32 `json:"core_block_height,string,omitempty"` // height of Chain Lock.
CoreBlockHash []byte `json:"core_block_hash,string,omitempty"` // hash of Chain Lock.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

BlockHash?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are 2 block hashes, one core and one platform, expressing which one I think makes this more easy to understand.

Comment thread types/block_test.go Resolved
Comment thread types/chainLock.go
return cl, cl.ValidateBasic()
}

func NewMockChainLock() ChainLock {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NewMockCoreChainLock

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's a chain lock, we only have 1 type in Dash

Comment thread types/block_meta.go
BlockID: BlockID{block.Hash(), blockParts.Header()},
BlockSize: block.Size(),
Header: block.Header,
HasChainLock: block.ChainLock != nil,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

HasCoreChainLock

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same as above.

Comment thread types/block.go

Header `json:"header"`
Data `json:"data"`
ChainLock *ChainLock `json:"chain_lock"`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CoreChainLock

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same as above.

Comment thread types/block.go
// MaxHeaderBytes is a maximum header size.
MaxHeaderBytes int64 = 626
MaxHeaderBytes int64 = 632
MaxChainLockSize int64 = 132

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

MaxCoreChainLockSize

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same as above.

Comment thread tests.mk

test100:
@for i in {1..100}; do make test; done
@for i in {1..100}; do make test; go clean -testcache; done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Have you run this test? @shumkov ? It does not work without it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@alexanderbez did you guys just forgot to add it in Tendermint?

Comment thread state/validation.go
}
}

//if block.Header.CoreChainLockedHeight < state.LastCoreBlockHeight {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It doesn't work for now?

Comment thread state/state_test.go

// Swap the first validator with a new one (validator set size stays the same).
header, blockID, responses := makeHeaderPartsResponsesValPubKeyChange(state, pubkey)
header, chainLock, blockID, responses := makeHeaderPartsResponsesValPubKeyChange(state, pubkey)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

coreChainLock

Comment thread state/state.go
LastBlockID: types.BlockID{},
LastBlockTime: genDoc.GenesisTime,

LastChainLock: lastChainLock,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LatestCoreChainLock?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

++

Comment thread state/execution.go

// Update the state with the block and responses.
state, err = updateState(state, blockID, &block.Header, abciResponses, validatorUpdates)
state, err = updateState(state, blockID, &block.Header, block.ChainLock, abciResponses, validatorUpdates)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I thought we update state from EndBlockResponse.lastestChainLock, do we?

int64 block_size = 2;
Header header = 3 [(gogoproto.nullable) = false];
int64 num_txs = 4;
bool has_chain_lock = 5;

@shumkov shumkov Oct 12, 2020 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

has_core_chain_lock? Btw, why do we need it meta?

tendermint.version.Consensus version = 1 [(gogoproto.nullable) = false];
string chain_id = 2 [(gogoproto.customname) = "ChainID"];
int64 height = 3;
uint32 core_chain_locked_height = 4;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's do not change fields order so Tendermint headers will be still compatible which could be important for IBC. We could add our fields with some gap in indices, like since 10000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, please! Proto fields should be appended only or removed entirely.

Comment thread abci/client/client.go
SetOptionAsync(types.RequestSetOption) *ReqRes
DeliverTxAsync(types.RequestDeliverTx) *ReqRes
CheckTxAsync(types.RequestCheckTx) *ReqRes
CheckQuorumSignatureAsync(types.RequestCheckQuorumSignature) *ReqRes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

++

Comment thread consensus/replay.go

// ApplyBlock on the proxyApp with the last block.
func (h *Handshaker) replayBlock(state sm.State, height int64, proxyApp proxy.AppConnConsensus) (sm.State, error) {
func (h *Handshaker) replayBlock(state sm.State, height int64, proxyApp proxy.AppConnConsensus, proxyAppValidation proxy.AppConnValidation) (sm.State, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the motivation for needing this argument?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We need to pass a connection to make a query. Probably it's better to just pass the whole proxyApp since we need two connections there?

Comment thread evidence/pool_test.go

lastCommit := makeCommit(height-1, valAddr)
block := types.MakeBlock(height, []types.Tx{}, lastCommit, []types.Evidence{})
block := types.MakeBlock(height,chainLock.CoreBlockHeight, &chainLock, []types.Tx{}, lastCommit, []types.Evidence{})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just pass chainLock in as a single variable?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We pass ChainLock only in case if we want to update it, otherwise, we just pass core block height from the previous block.

// VoteInfo
message ChainLockParam {
// Note: must be greater than 0
uint32 chain_lock_height = 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These names clobber a bit. Consider removing chain_lock prefixes from the fields.

tendermint.version.Consensus version = 1 [(gogoproto.nullable) = false];
string chain_id = 2 [(gogoproto.customname) = "ChainID"];
int64 height = 3;
uint32 core_chain_locked_height = 4;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, please! Proto fields should be appended only or removed entirely.

Comment thread state/state.go
LastBlockID: types.BlockID{},
LastBlockTime: genDoc.GenesisTime,

LastChainLock: lastChainLock,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

++

@QuantumExplorer

Copy link
Copy Markdown
Member Author

This is being replaced by PR 5

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.

3 participants