Sync only missing blocks on cold import

= Add eth_node_fingerprint to block that can be imitated by both hot and cold imports
- Only sync missing blocks (blocks that are missing or don't share a fingerprint) on cold import
- Set block is_final status after import
This commit is contained in:
Rob Mulholand
2018-05-07 16:38:04 -05:00
parent 5a5e08bd13
commit d5c2ab33fc
31 changed files with 616 additions and 171 deletions
+46 -11
View File
@@ -7,18 +7,32 @@ import (
)
type MockBlockRepository struct {
createOrUpdateBlockCalled bool
createOrUpdateBlockPassedBlock core.Block
createOrUpdateBlockReturnInt int64
createOrUpdateBlockReturnErr error
createOrUpdateBlockCalled bool
createOrUpdateBlockPassedBlock core.Block
createOrUpdateBlockReturnInt int64
createOrUpdateBlockReturnErr error
missingBlockNumbersCalled bool
missingBlockNumbersPassedStartingBlockNumber int64
missingBlockNumbersPassedEndingBlockNumber int64
missingBlockNumbersPassedNodeId string
missingBlockNumbersReturnArray []int64
setBlockStatusCalled bool
setBlockStatusPassedChainHead int64
}
func NewMockBlockRepository() *MockBlockRepository {
return &MockBlockRepository{
createOrUpdateBlockCalled: false,
createOrUpdateBlockPassedBlock: core.Block{},
createOrUpdateBlockReturnInt: 0,
createOrUpdateBlockReturnErr: nil,
createOrUpdateBlockCalled: false,
createOrUpdateBlockPassedBlock: core.Block{},
createOrUpdateBlockReturnInt: 0,
createOrUpdateBlockReturnErr: nil,
missingBlockNumbersCalled: false,
missingBlockNumbersPassedStartingBlockNumber: 0,
missingBlockNumbersPassedEndingBlockNumber: 0,
missingBlockNumbersPassedNodeId: "",
missingBlockNumbersReturnArray: nil,
setBlockStatusCalled: false,
setBlockStatusPassedChainHead: 0,
}
}
@@ -27,6 +41,10 @@ func (mbr *MockBlockRepository) SetCreateOrUpdateBlockReturnVals(i int64, err er
mbr.createOrUpdateBlockReturnErr = err
}
func (mbr *MockBlockRepository) SetMissingBlockNumbersReturnArray(returnArray []int64) {
mbr.missingBlockNumbersReturnArray = returnArray
}
func (mbr *MockBlockRepository) CreateOrUpdateBlock(block core.Block) (int64, error) {
mbr.createOrUpdateBlockCalled = true
mbr.createOrUpdateBlockPassedBlock = block
@@ -37,15 +55,32 @@ func (mbr *MockBlockRepository) GetBlock(blockNumber int64) (core.Block, error)
panic("implement me")
}
func (mbr *MockBlockRepository) MissingBlockNumbers(startingBlockNumber int64, endingBlockNumber int64) []int64 {
panic("implement me")
func (mbr *MockBlockRepository) MissingBlockNumbers(startingBlockNumber int64, endingBlockNumber int64, nodeId string) []int64 {
mbr.missingBlockNumbersCalled = true
mbr.missingBlockNumbersPassedStartingBlockNumber = startingBlockNumber
mbr.missingBlockNumbersPassedEndingBlockNumber = endingBlockNumber
mbr.missingBlockNumbersPassedNodeId = nodeId
return mbr.missingBlockNumbersReturnArray
}
func (mbr *MockBlockRepository) SetBlocksStatus(chainHead int64) {
panic("implement me")
mbr.setBlockStatusCalled = true
mbr.setBlockStatusPassedChainHead = chainHead
}
func (mbr *MockBlockRepository) AssertCreateOrUpdateBlockCalledWith(block core.Block) {
Expect(mbr.createOrUpdateBlockCalled).To(BeTrue())
Expect(mbr.createOrUpdateBlockPassedBlock).To(Equal(block))
}
func (mbr *MockBlockRepository) AssertMissingBlockNumbersCalledWith(startingBlockNumber int64, endingBlockNumber int64, nodeId string) {
Expect(mbr.missingBlockNumbersCalled).To(BeTrue())
Expect(mbr.missingBlockNumbersPassedStartingBlockNumber).To(Equal(startingBlockNumber))
Expect(mbr.missingBlockNumbersPassedEndingBlockNumber).To(Equal(endingBlockNumber))
Expect(mbr.missingBlockNumbersPassedNodeId).To(Equal(nodeId))
}
func (mbr *MockBlockRepository) AssertSetBlockStatusCalledWith(chainHead int64) {
Expect(mbr.setBlockStatusCalled).To(BeTrue())
Expect(mbr.setBlockStatusPassedChainHead).To(Equal(chainHead))
}
+38
View File
@@ -0,0 +1,38 @@
package fakes
import . "github.com/onsi/gomega"
type MockCryptoParser struct {
parsePublicKeyCalled bool
parsePublicKeyPassedPrivateKey string
parsePublicKeyReturnString string
parsePublicKeyReturnErr error
}
func NewMockCryptoParser() *MockCryptoParser {
return &MockCryptoParser{
parsePublicKeyCalled: false,
parsePublicKeyPassedPrivateKey: "",
parsePublicKeyReturnString: "",
parsePublicKeyReturnErr: nil,
}
}
func (mcp *MockCryptoParser) SetReturnVal(pubKey string) {
mcp.parsePublicKeyReturnString = pubKey
}
func (mcp *MockCryptoParser) SetReturnErr(err error) {
mcp.parsePublicKeyReturnErr = err
}
func (mcp *MockCryptoParser) ParsePublicKey(privateKey string) (string, error) {
mcp.parsePublicKeyCalled = true
mcp.parsePublicKeyPassedPrivateKey = privateKey
return mcp.parsePublicKeyReturnString, mcp.parsePublicKeyReturnErr
}
func (mcp *MockCryptoParser) AssertParsePublicKeyCalledWith(privateKey string) {
Expect(mcp.parsePublicKeyCalled).To(BeTrue())
Expect(mcp.parsePublicKeyPassedPrivateKey).To(Equal(privateKey))
}
+38
View File
@@ -0,0 +1,38 @@
package fakes
import . "github.com/onsi/gomega"
type MockFsReader struct {
readCalled bool
readPassedPath string
readReturnBytes []byte
readReturnErr error
}
func NewMockFsReader() *MockFsReader {
return &MockFsReader{
readCalled: false,
readPassedPath: "",
readReturnBytes: nil,
readReturnErr: nil,
}
}
func (mfr *MockFsReader) SetReturnBytes(returnBytes []byte) {
mfr.readReturnBytes = returnBytes
}
func (mfr *MockFsReader) SetReturnErr(err error) {
mfr.readReturnErr = err
}
func (mfr *MockFsReader) Read(path string) ([]byte, error) {
mfr.readCalled = true
mfr.readPassedPath = path
return mfr.readReturnBytes, mfr.readReturnErr
}
func (mfr *MockFsReader) AssertReadCalledWith(path string) {
Expect(mfr.readCalled).To(BeTrue())
Expect(mfr.readPassedPath).To(Equal(path))
}