diff --git a/common/query/blockQuery.go b/common/query/blockQuery.go index ef3ae6496..70d212aef 100644 --- a/common/query/blockQuery.go +++ b/common/query/blockQuery.go @@ -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 diff --git a/common/query/blockQuery_test.go b/common/query/blockQuery_test.go index 51301cbee..38faaf2ce 100644 --- a/common/query/blockQuery_test.go +++ b/common/query/blockQuery_test.go @@ -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 { diff --git a/core/service/snapshotMainBlockService.go b/core/service/snapshotMainBlockService.go index 764761ae6..876a62fa9 100644 --- a/core/service/snapshotMainBlockService.go +++ b/core/service/snapshotMainBlockService.go @@ -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