Browse Source

post rebase fixes for BlockID, partSize

pull/265/head
Ethan Buchman 8 years ago
parent
commit
07597dfd45
8 changed files with 46 additions and 32 deletions
  1. +1
    -1
      consensus/state.go
  2. +1
    -1
      glide.lock
  3. +2
    -2
      node/node.go
  4. +9
    -8
      state/execution.go
  5. +21
    -14
      state/execution_test.go
  6. +1
    -1
      state/state.go
  7. +2
    -2
      types/block.go
  8. +9
    -3
      types/protobuf.go

+ 1
- 1
consensus/state.go View File

@ -933,7 +933,7 @@ func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts
txs := cs.mempool.Reap(cs.config.GetInt("block_size"))
return types.MakeBlock(cs.Height, cs.state.ChainID, txs, commit,
cs.state.LastBlockID, cs.state.Validators.Hash(), cs.state.AppHash)
cs.state.LastBlockID, cs.state.Validators.Hash(), cs.state.AppHash, cs.config.GetInt("block_part_size"))
}
// Enter: `timeoutPropose` after entering Propose.


+ 1
- 1
glide.lock View File

@ -92,7 +92,7 @@ imports:
subpackages:
- term
- name: github.com/tendermint/tmsp
version: fec038bdec3495a2a06c6aa8f63e9716bad335dd
version: 60e0842ef9a87c840d0bf95eea7b54a1e3d312b3
subpackages:
- client
- example/counter


+ 2
- 2
node/node.go View File

@ -63,7 +63,7 @@ func NewNode(config cfg.Config, privValidator *types.PrivValidator, clientCreato
state := sm.GetState(config, stateDB)
// Create the proxyApp, which manages connections (consensus, mempool, query)
proxyApp := proxy.NewAppConns(config, clientCreator, sm.NewHandshaker(state, blockStore))
proxyApp := proxy.NewAppConns(config, clientCreator, sm.NewHandshaker(config, state, blockStore))
if _, err := proxyApp.Start(); err != nil {
Exit(Fmt("Error starting proxy app connections: %v", err))
}
@ -380,7 +380,7 @@ func newConsensusState(config cfg.Config) *consensus.ConsensusState {
state := sm.MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file"))
// Create proxyAppConn connection (consensus, mempool, query)
proxyApp := proxy.NewAppConns(config, proxy.DefaultClientCreator(config), sm.NewHandshaker(state, blockStore))
proxyApp := proxy.NewAppConns(config, proxy.DefaultClientCreator(config), sm.NewHandshaker(config, state, blockStore))
_, err := proxyApp.Start()
if err != nil {
Exit(Fmt("Error starting proxy app conns: %v", err))


+ 9
- 8
state/execution.go View File

@ -7,6 +7,7 @@ import (
"github.com/ebuchman/fail-test"
. "github.com/tendermint/go-common"
cfg "github.com/tendermint/go-config"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
tmsp "github.com/tendermint/tmsp/types"
@ -261,14 +262,15 @@ type BlockStore interface {
}
type Handshaker struct {
state *State
store BlockStore
config cfg.Config
state *State
store BlockStore
nBlocks int // number of blocks applied to the state
}
func NewHandshaker(state *State, store BlockStore) *Handshaker {
return &Handshaker{state, store, 0}
func NewHandshaker(config cfg.Config, state *State, store BlockStore) *Handshaker {
return &Handshaker{config, state, store, 0}
}
// TODO: retry the handshake once if it fails the first time
@ -320,7 +322,7 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
}*/
header = block.Header
partsHeader = block.MakePartSet().Header()
partsHeader = block.MakePartSet(h.config.GetInt("block_part_size")).Header()
}
if configInfo != nil {
@ -355,8 +357,7 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, header *types.Header, partsHea
lastVals, nextVals := stateCopy.GetValidators()
if header == nil {
stateCopy.LastBlockHeight = 0
stateCopy.LastBlockHash = nil
stateCopy.LastBlockParts = types.PartSetHeader{}
stateCopy.LastBlockID = types.BlockID{}
// stateCopy.LastBlockTime = ... doesnt matter
stateCopy.Validators = nextVals
stateCopy.LastValidators = lastVals
@ -422,7 +423,7 @@ func (h *Handshaker) loadApplyBlock(blockIndex int, state *State, appConnConsens
block := h.store.LoadBlock(blockIndex)
panicOnNilBlock(blockIndex, h.store.Height(), block) // XXX
var eventCache types.Fireable // nil
return state.ApplyBlock(eventCache, appConnConsensus, block, block.MakePartSet().Header(), mockMempool{})
return state.ApplyBlock(eventCache, appConnConsensus, block, block.MakePartSet(h.config.GetInt("block_part_size")).Header(), mockMempool{})
}
func panicOnNilBlock(height, bsHeight int, block *types.Block) {


+ 21
- 14
state/execution_test.go View File

@ -2,7 +2,7 @@ package state
import (
"bytes"
//"fmt"
"fmt"
"path"
"testing"
@ -16,10 +16,11 @@ import (
)
var (
privKey = crypto.GenPrivKeyEd25519FromSecret([]byte("handshake_test"))
chainID = "handshake_chain"
nBlocks = 5
mempool = mockMempool{}
privKey = crypto.GenPrivKeyEd25519FromSecret([]byte("handshake_test"))
chainID = "handshake_chain"
nBlocks = 5
mempool = mockMempool{}
testPartSize = 65536
)
func TestExecBlock(t *testing.T) {
@ -53,7 +54,7 @@ func testHandshakeReplay(t *testing.T, n int) {
state, store := stateAndStore()
clientCreator := proxy.NewLocalClientCreator(dummy.NewPersistentDummyApplication(path.Join(config.GetString("db_dir"), "1")))
clientCreator2 := proxy.NewLocalClientCreator(dummy.NewPersistentDummyApplication(path.Join(config.GetString("db_dir"), "2")))
proxyApp := proxy.NewAppConns(config, clientCreator, NewHandshaker(state, store))
proxyApp := proxy.NewAppConns(config, clientCreator, NewHandshaker(config, state, store))
if _, err := proxyApp.Start(); err != nil {
t.Fatalf("Error starting proxy app connections: %v", err)
}
@ -71,7 +72,7 @@ func testHandshakeReplay(t *testing.T, n int) {
state2, _ := stateAndStore()
for i := 0; i < n; i++ {
block := chain[i]
err := state2.ApplyBlock(nil, proxyApp.Consensus(), block, block.MakePartSet().Header(), mempool)
err := state2.ApplyBlock(nil, proxyApp.Consensus(), block, block.MakePartSet(testPartSize).Header(), mempool)
if err != nil {
t.Fatal(err)
}
@ -80,7 +81,7 @@ func testHandshakeReplay(t *testing.T, n int) {
}
// now start it with the handshake
handshaker := NewHandshaker(state, store)
handshaker := NewHandshaker(config, state, store)
proxyApp = proxy.NewAppConns(config, clientCreator2, handshaker)
if _, err := proxyApp.Start(); err != nil {
t.Fatalf("Error starting proxy app connections: %v", err)
@ -116,11 +117,12 @@ func txsFunc(blockNum int) (txs []types.Tx) {
// sign a commit vote
func signCommit(height, round int, hash []byte, header types.PartSetHeader) *types.Vote {
vote := &types.Vote{
ValidatorIndex: 0,
ValidatorAddress: privKey.PubKey().Address(),
Height: height,
Round: round,
Type: types.VoteTypePrecommit,
BlockHash: hash,
BlockPartsHeader: header,
BlockID: types.BlockID{hash, header},
}
sig := privKey.Sign(types.SignBytes(chainID, vote))
@ -131,22 +133,26 @@ func signCommit(height, round int, hash []byte, header types.PartSetHeader) *typ
// make a blockchain with one validator
func makeBlockchain(t *testing.T, proxyApp proxy.AppConns, state *State) (blockchain []*types.Block) {
prevHash := state.LastBlockHash
prevHash := state.LastBlockID.Hash
lastCommit := new(types.Commit)
prevParts := types.PartSetHeader{}
valHash := state.Validators.Hash()
prevBlockID := types.BlockID{prevHash, prevParts}
for i := 1; i < nBlocks+1; i++ {
block, parts := types.MakeBlock(i, chainID, txsFunc(i), lastCommit,
prevParts, prevHash, valHash, state.AppHash)
err := state.ApplyBlock(nil, proxyApp.Consensus(), block, block.MakePartSet().Header(), mempool)
prevBlockID, valHash, state.AppHash, testPartSize)
fmt.Println(i)
fmt.Println(prevBlockID)
fmt.Println(block.LastBlockID)
err := state.ApplyBlock(nil, proxyApp.Consensus(), block, block.MakePartSet(testPartSize).Header(), mempool)
if err != nil {
t.Fatal(i, err)
}
voteSet := types.NewVoteSet(chainID, i, 0, types.VoteTypePrecommit, state.Validators)
vote := signCommit(i, 0, block.Hash(), parts.Header())
_, _, err = voteSet.AddByIndex(0, vote)
_, err = voteSet.AddVote(vote)
if err != nil {
t.Fatal(err)
}
@ -155,6 +161,7 @@ func makeBlockchain(t *testing.T, proxyApp proxy.AppConns, state *State) (blockc
prevHash = block.Hash()
prevParts = parts.Header()
lastCommit = voteSet.MakeCommit()
prevBlockID = types.BlockID{prevHash, prevParts}
}
return blockchain
}


+ 1
- 1
state/state.go View File

@ -97,7 +97,7 @@ func (s *State) Bytes() []byte {
// Since we don't have the new AppHash yet, we set s.Stale=true
func (s *State) SetBlockAndValidators(header *types.Header, blockPartsHeader types.PartSetHeader, prevValSet, nextValSet *types.ValidatorSet) {
s.LastBlockHeight = header.Height
s.LastBlockID = types.BlockID{block.Hash(), blockPartsHeader}
s.LastBlockID = types.BlockID{header.Hash(), blockPartsHeader}
s.LastBlockTime = header.Time
s.Validators = nextValSet
s.LastValidators = prevValSet


+ 2
- 2
types/block.go View File

@ -22,7 +22,7 @@ type Block struct {
}
func MakeBlock(height int, chainID string, txs []Tx, commit *Commit,
prevBlockID BlockID, valHash, appHash []byte) (*Block, *PartSet) {
prevBlockID BlockID, valHash, appHash []byte, partSize int) (*Block, *PartSet) {
block := &Block{
Header: &Header{
ChainID: chainID,
@ -39,7 +39,7 @@ func MakeBlock(height int, chainID string, txs []Tx, commit *Commit,
},
}
block.FillHeader()
return block, block.MakePartSet()
return block, block.MakePartSet(partSize)
}
// Basic validation that doesn't involve state data.


+ 9
- 3
types/protobuf.go View File

@ -12,17 +12,23 @@ type tm2pb struct{}
func (tm2pb) Header(header *Header) *types.Header {
return &types.Header{
ChainId: header.ChainID,
Height: uint64(header.Height),
Height: int32(header.Height),
Time: uint64(header.Time.Unix()),
NumTxs: uint64(header.NumTxs),
LastBlockHash: header.LastBlockHash,
LastBlockParts: TM2PB.PartSetHeader(header.LastBlockParts),
LastBlockId: TM2PB.BlockID(header.LastBlockID),
LastCommitHash: header.LastCommitHash,
DataHash: header.DataHash,
AppHash: header.AppHash,
}
}
func (tm2pb) BlockID(blockID BlockID) *types.BlockID {
return &types.BlockID{
Hash: blockID.Hash,
Parts: TM2PB.PartSetHeader(blockID.PartsHeader),
}
}
func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) *types.PartSetHeader {
return &types.PartSetHeader{
Total: uint64(partSetHeader.Total),


Loading…
Cancel
Save