Skip to content

Commit

Permalink
fix rollup batches order query
Browse files Browse the repository at this point in the history
  • Loading branch information
badgersrus committed Apr 30, 2024
1 parent 9eb1e66 commit ea4a0a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions go/host/storage/hostdb/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const (
selectExtRollup = "SELECT ext_rollup from rollup_host r"
selectLatestRollup = "SELECT ext_rollup FROM rollup_host ORDER BY time_stamp DESC LIMIT 1"
selectRollupBatches = "SELECT b.sequence, b.hash, b.full_hash, b.height, b.ext_batch FROM rollup_host r JOIN batch_host b ON r.start_seq <= b.sequence AND r.end_seq >= b.sequence ORDER BY b.height DESC"
selectRollupBatches = "SELECT b.sequence, b.hash, b.full_hash, b.height, b.ext_batch FROM rollup_host r JOIN batch_host b ON r.start_seq <= b.sequence AND r.end_seq >= b.sequence"
selectPublicRollup = "SELECT id, hash, start_seq, end_seq, time_stamp, ext_rollup, compression_block FROM rollup_host"
)

Expand Down Expand Up @@ -125,10 +125,11 @@ func GetRollupBySeqNo(db HostDB, seqNo uint64) (*common.PublicRollup, error) {

func GetRollupBatches(db HostDB, rollupHash gethcommon.Hash) (*common.BatchListingResponse, error) {
whereQuery := " WHERE r.hash=" + db.GetSQLStatement().Placeholder
query := selectRollupBatches + whereQuery
orderQuery := " ORDER BY b.height DESC"
query := selectRollupBatches + whereQuery + orderQuery
rows, err := db.GetSQLDB().Query(query, truncTo16(rollupHash))
if err != nil {
return nil, fmt.Errorf("query execution for select txs failed: %w", err)
return nil, fmt.Errorf("query execution for select rollup batches failed: %w", err)
}
defer rows.Close()

Expand Down
8 changes: 4 additions & 4 deletions go/host/storage/hostdb/rollup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ func TestGetRollupBatches(t *testing.T) {
t.Errorf("batch listing was not calculated correctly")
}

// second element should be batch 2
if batchListing.BatchesData[1].Header.SequencerOrderNo.Cmp(batchTwo.SeqNo()) != 0 {
// second element should be batch 1 as we're ordering by height descending
if batchListing.BatchesData[1].Header.SequencerOrderNo.Cmp(batchOne.SeqNo()) != 0 {
t.Errorf("batch listing was not returned correctly")
}

Expand All @@ -374,8 +374,8 @@ func TestGetRollupBatches(t *testing.T) {
if big.NewInt(int64(batchListing1.Total)).Cmp(big.NewInt(2)) != 0 {
t.Errorf("batch listing was not calculated correctly")
}
// second element should be batch 4
if batchListing1.BatchesData[1].Header.SequencerOrderNo.Cmp(batchFour.SeqNo()) != 0 {
// second element should be batch 3 as we're ordering by height descending
if batchListing1.BatchesData[1].Header.SequencerOrderNo.Cmp(batchThree.SeqNo()) != 0 {
t.Errorf("batch listing was not returned correctly")
}
}
Expand Down

0 comments on commit ea4a0a2

Please sign in to comment.