Skip to content

Include more blocks in snapshots #719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/query/blockQuery.go
Original file line number Diff line number Diff line change
@@ -194,8 +194,8 @@ func (bq *BlockQuery) Rollback(height uint32) (multiQueries [][]interface{}) {

// SelectDataForSnapshot select only the block at snapshot height (fromHeight is unused)
func (bq *BlockQuery) SelectDataForSnapshot(fromHeight, toHeight uint32) string {
return fmt.Sprintf(`SELECT %s FROM %s WHERE height = %d`,
strings.Join(bq.Fields, ","), bq.getTableName(), toHeight)
return fmt.Sprintf(`SELECT %s FROM %s WHERE height >= %d AND height <= %d`,
strings.Join(bq.Fields, ","), bq.getTableName(), fromHeight, toHeight)
}

// TrimDataBeforeSnapshot delete entries to assure there are no duplicates before applying a snapshot
2 changes: 1 addition & 1 deletion common/query/blockQuery_test.go
Original file line number Diff line number Diff line change
@@ -357,7 +357,7 @@ func TestBlockQuery_SelectDataForSnapshot(t *testing.T) {
},
want: "SELECT id,block_hash,previous_block_hash,height,timestamp,block_seed,block_signature," +
"cumulative_difficulty,payload_length,payload_hash,blocksmith_public_key,total_amount,total_fee,total_coinbase," +
"version FROM main_block WHERE height = 10",
"version FROM main_block WHERE height >= 0 AND height <= 10",
},
}
for _, tt := range tests {
5 changes: 5 additions & 0 deletions core/service/snapshotMainBlockService.go
Original file line number Diff line number Diff line change
@@ -98,6 +98,11 @@ func (ss *SnapshotMainBlockService) NewSnapshotFile(block *model.Block) (snapsho
fromHeight uint32
rows *sql.Rows
)
if qryRepoName == "block" {
if snapshotPayloadHeight > constant.MinRollbackBlocks {
fromHeight = snapshotPayloadHeight - constant.MinRollbackBlocks
}
}
if qryRepoName == "publishedReceipt" {
if snapshotPayloadHeight > constant.LinkedReceiptBlocksLimit {
fromHeight = snapshotPayloadHeight - constant.LinkedReceiptBlocksLimit