blockchain: use ApplyBlock

This commit is contained in:
Ethan Buchman
2016-12-06 23:01:55 -05:00
parent 6be5bda8c9
commit 2425711734
3 changed files with 13 additions and 18 deletions

View File

@ -235,23 +235,18 @@ FOR_LOOP:
break SYNC_LOOP break SYNC_LOOP
} else { } else {
bcR.pool.PopRequest() bcR.pool.PopRequest()
// TODO: use ApplyBlock instead of Exec/Commit/SetAppHash/Save
bcR.store.SaveBlock(first, firstParts, second.LastCommit)
// TODO: should we be firing events? need to fire NewBlock events manually ... // TODO: should we be firing events? need to fire NewBlock events manually ...
err := bcR.state.ExecBlock(bcR.evsw, bcR.proxyAppConn, first, firstPartsHeader) // NOTE: we could improve performance if we
// didn't make the app commit to disk every block
// ... but we would need a way to get the hash without it persisting
err := bcR.state.ApplyBlock(bcR.evsw, bcR.proxyAppConn, first, firstPartsHeader, sm.MockMempool{})
if err != nil { if err != nil {
// TODO This is bad, are we zombie? // TODO This is bad, are we zombie?
PanicQ(Fmt("Failed to process committed block (%d:%X): %v", first.Height, first.Hash(), err)) PanicQ(Fmt("Failed to process committed block (%d:%X): %v", first.Height, first.Hash(), err))
} }
// NOTE: we could improve performance if we
// didn't make the app commit to disk every block
// ... but we would need a way to get the hash without it persisting
res := bcR.proxyAppConn.CommitSync()
if res.IsErr() {
// TODO Handle gracefully.
PanicQ(Fmt("Failed to commit block at application: %v", res))
}
bcR.store.SaveBlock(first, firstParts, second.LastCommit)
bcR.state.AppHash = res.Data
bcR.state.Save() bcR.state.Save()
} }
} }

View File

@ -280,12 +280,12 @@ type Mempool interface {
Update(height int, txs []types.Tx) Update(height int, txs []types.Tx)
} }
type mockMempool struct { type MockMempool struct {
} }
func (m mockMempool) Lock() {} func (m MockMempool) Lock() {}
func (m mockMempool) Unlock() {} func (m MockMempool) Unlock() {}
func (m mockMempool) Update(height int, txs []types.Tx) {} func (m MockMempool) Update(height int, txs []types.Tx) {}
//---------------------------------------------------------------- //----------------------------------------------------------------
// Handshake with app to sync to latest state of core by replaying blocks // Handshake with app to sync to latest state of core by replaying blocks
@ -386,7 +386,7 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, appConnCon
var eventCache types.Fireable // nil var eventCache types.Fireable // nil
// replay the block against the actual tendermint state // replay the block against the actual tendermint state
return h.state.ApplyBlock(eventCache, appConnConsensus, block, blockMeta.PartsHeader, mockMempool{}) return h.state.ApplyBlock(eventCache, appConnConsensus, block, blockMeta.PartsHeader, MockMempool{})
} else { } else {
// either we're caught up or there's blocks to replay // either we're caught up or there's blocks to replay

View File

@ -20,7 +20,7 @@ var (
privKey = crypto.GenPrivKeyEd25519FromSecret([]byte("handshake_test")) privKey = crypto.GenPrivKeyEd25519FromSecret([]byte("handshake_test"))
chainID = "handshake_chain" chainID = "handshake_chain"
nBlocks = 5 nBlocks = 5
mempool = mockMempool{} mempool = MockMempool{}
testPartSize = 65536 testPartSize = 65536
) )