Skip to content

Hotfix rows immediate release #749

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 4 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions common/database/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ func (m *Migration) Init() error {
`
CREATE INDEX "node_receipt_reference_block_height_idx" ON "node_receipt" ("reference_block_height")
`,
`
CREATE INDEX "published_receipt_datum_hash_idx" ON "published_receipt" ("datum_hash")
`,
}
return nil
}
Expand Down
49 changes: 23 additions & 26 deletions core/service/receiptService.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (rs *ReceiptService) SelectReceipts(
pickedRecipients = make(map[string]bool)
lowerBlockHeight uint32
linkedReceiptTree = make(map[string][]byte)
err error
)

if numberOfReceipt < 1 { // possible no connected node
Expand All @@ -108,38 +109,35 @@ func (rs *ReceiptService) SelectReceipts(
lowerBlockHeight = lastBlockHeight - constant.MinRollbackBlocks
}

err := func() error {
linkedReceiptTree, err = func() (map[string][]byte, error) {
treeQ := rs.MerkleTreeQuery.SelectMerkleTree(
lowerBlockHeight,
lastBlockHeight,
numberOfReceipt*constant.ReceiptBatchPickMultiplier)
linkedTreeRows, err := rs.QueryExecutor.ExecuteSelect(treeQ, false)
if err != nil {
return err
return linkedReceiptTree, err
}
defer linkedTreeRows.Close()

linkedReceiptTree, err = rs.MerkleTreeQuery.BuildTree(linkedTreeRows)
if err != nil {
return err
}
return nil
return rs.MerkleTreeQuery.BuildTree(linkedTreeRows)
}()
if err != nil {
return nil, err
}

for linkedRoot := range linkedReceiptTree {
var nodeReceipts []*model.Receipt
nodeReceiptsQ, rootArgs := rs.NodeReceiptQuery.GetReceiptByRoot([]byte(linkedRoot))
rows, err := rs.QueryExecutor.ExecuteSelect(nodeReceiptsQ, false, rootArgs...)
if err != nil {
return nil, err
}

nodeReceipts, err = rs.NodeReceiptQuery.BuildModel(nodeReceipts, rows)
nodeReceipts, err = func() ([]*model.Receipt, error) {
nodeReceiptsQ, rootArgs := rs.NodeReceiptQuery.GetReceiptByRoot([]byte(linkedRoot))
rows, err := rs.QueryExecutor.ExecuteSelect(nodeReceiptsQ, false, rootArgs...)
if err != nil {
return nil, err
}
defer rows.Close()
return rs.NodeReceiptQuery.BuildModel(nodeReceipts, rows)
}()
if err != nil {
rows.Close()
return nil, err
}
for _, rc := range nodeReceipts {
Expand All @@ -148,9 +146,6 @@ func (rs *ReceiptService) SelectReceipts(
linkedReceiptList[linkedRoot] = append(linkedReceiptList[linkedRoot], rc)
}
}
if rows != nil {
rows.Close()
}
}
// limit the selected portion to `numberOfReceipt` receipts
// filter the selected receipts on second phase
Expand Down Expand Up @@ -210,14 +205,16 @@ func (rs *ReceiptService) pickReceipts(
lowerBlockHeight, upperBlockHeight uint32,
) ([]*model.PublishedReceipt, error) {
var receipts []*model.Receipt
receiptsQ := rs.NodeReceiptQuery.GetReceiptsWithUniqueRecipient(
numberOfReceipt*constant.ReceiptBatchPickMultiplier, lowerBlockHeight, upperBlockHeight)
rows, err := rs.QueryExecutor.ExecuteSelect(receiptsQ, false)
if err != nil {
return nil, err
}
defer rows.Close()
receipts, err = rs.NodeReceiptQuery.BuildModel(receipts, rows)
receipts, err := func() ([]*model.Receipt, error) {
receiptsQ := rs.NodeReceiptQuery.GetReceiptsWithUniqueRecipient(
numberOfReceipt*constant.ReceiptBatchPickMultiplier, lowerBlockHeight, upperBlockHeight)
rows, err := rs.QueryExecutor.ExecuteSelect(receiptsQ, false)
if err != nil {
return nil, err
}
defer rows.Close()
return rs.NodeReceiptQuery.BuildModel(receipts, rows)
}()
if err != nil {
return nil, err
}
Expand Down