Skip to content

Commit 9f9a1da

Browse files
committed
Return newBlock instead of duplicate from ProcessBlock
Rename the ProcessBlock return value from duplicate to newBlock to align with the C API parameter naming.
1 parent f0c9fab commit 9f9a1da

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

kernel/chainstate_manager.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ func (cm *ChainstateManager) ReadBlockSpentOutputs(blockTreeEntry *BlockTreeEntr
118118
// - block: Block to validate and potentially add to the chain
119119
//
120120
// Returns ok=true if processing the block was successful (will also return true for valid,
121-
// but duplicate blocks) and duplicate=false if this block was not processed before. Note that
122-
// duplicate might also be false if processing was attempted before, but the block was found
121+
// but duplicate blocks) and newBlock=true if this block was not processed before. Note that
122+
// newBlock might also be true if processing was attempted before, but the block was found
123123
// invalid before its data was persisted.
124-
func (cm *ChainstateManager) ProcessBlock(block *Block) (ok bool, duplicate bool) {
125-
var newBlock C.int
126-
result := C.btck_chainstate_manager_process_block((*C.btck_ChainstateManager)(cm.ptr), (*C.btck_Block)(block.ptr), &newBlock)
124+
func (cm *ChainstateManager) ProcessBlock(block *Block) (ok bool, newBlock bool) {
125+
var newBlockInt C.int
126+
result := C.btck_chainstate_manager_process_block((*C.btck_ChainstateManager)(cm.ptr), (*C.btck_Block)(block.ptr), &newBlockInt)
127127
ok = result == 0
128-
duplicate = newBlock == 0
128+
newBlock = newBlockInt == 1
129129
return
130130
}
131131

kernel/chainstate_manager_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,13 @@ func (s *ChainstateManagerTestSuite) Setup(t *testing.T) {
317317
}
318318
defer block.Destroy()
319319

320-
ok, duplicate := manager.ProcessBlock(block)
321-
if !ok || duplicate {
320+
ok, newBlock := manager.ProcessBlock(block)
321+
if !ok {
322322
t.Fatalf("ProcessBlock() failed for block %d", i+1)
323323
}
324+
if !newBlock {
325+
t.Fatalf("ProcessBlock() returned newBlock=false for block %d (block data was already on disk)", i+1)
326+
}
324327
}
325328

326329
s.Manager = manager

0 commit comments

Comments
 (0)