Skip to content

Commit 5dfcd92

Browse files
authored
make GetUtxoViewAndUtxoOpsAtBlockHash public (#1422)
1 parent bc64e75 commit 5dfcd92

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

lib/pos_blockchain.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (bc *Blockchain) processBlockPoS(block *MsgDeSoBlock, currentView uint64, v
310310

311311
// We expect the utxoView for the parent block to be valid because we check that all ancestor blocks have
312312
// been validated.
313-
parentUtxoViewAndUtxoOps, err := bc.getUtxoViewAndUtxoOpsAtBlockHash(*block.Header.PrevBlockHash)
313+
parentUtxoViewAndUtxoOps, err := bc.GetUtxoViewAndUtxoOpsAtBlockHash(*block.Header.PrevBlockHash)
314314
if err != nil {
315315
// This should never happen. If the parent is validated and extends from the tip, then we should
316316
// be able to build a UtxoView for it. This failure can only happen due to transient or badger issues.
@@ -814,7 +814,7 @@ func (bc *Blockchain) validatePreviouslyIndexedBlockPoS(
814814
return nil, errors.Wrapf(err, "validatePreviouslyIndexedBlockPoS: Problem fetching block from DB")
815815
}
816816
// Build utxoView for the block's parent.
817-
parentUtxoViewAndUtxoOps, err := bc.getUtxoViewAndUtxoOpsAtBlockHash(*block.Header.PrevBlockHash)
817+
parentUtxoViewAndUtxoOps, err := bc.GetUtxoViewAndUtxoOpsAtBlockHash(*block.Header.PrevBlockHash)
818818
if err != nil {
819819
// This should never happen. If the parent is validated and extends from the tip, then we should
820820
// be able to build a UtxoView for it. This failure can only happen due to transient or badger issues.
@@ -1720,7 +1720,7 @@ func (bc *Blockchain) commitBlockPoS(blockHash *BlockHash, verifySignatures bool
17201720
return errors.Errorf("commitBlockPoS: Block %v is already committed", blockHash.String())
17211721
}
17221722
// Connect a view up to block we are committing.
1723-
utxoViewAndUtxoOps, err := bc.getUtxoViewAndUtxoOpsAtBlockHash(*blockHash)
1723+
utxoViewAndUtxoOps, err := bc.GetUtxoViewAndUtxoOpsAtBlockHash(*blockHash)
17241724
if err != nil {
17251725
return errors.Wrapf(err, "commitBlockPoS: Problem initializing UtxoView: ")
17261726
}
@@ -1892,7 +1892,7 @@ func (viewAndUtxoOps *BlockViewAndUtxoOps) Copy() *BlockViewAndUtxoOps {
18921892
// GetUncommittedTipView builds a UtxoView to the uncommitted tip.
18931893
func (bc *Blockchain) GetUncommittedTipView() (*UtxoView, error) {
18941894
// Connect the uncommitted blocks to the tip so that we can validate subsequent blocks
1895-
blockViewAndUtxoOps, err := bc.getUtxoViewAndUtxoOpsAtBlockHash(*bc.BlockTip().Hash)
1895+
blockViewAndUtxoOps, err := bc.GetUtxoViewAndUtxoOpsAtBlockHash(*bc.BlockTip().Hash)
18961896
if err != nil {
18971897
return nil, errors.Wrapf(err, "GetUncommittedTipView: Problem getting UtxoView at block hash")
18981898
}
@@ -1906,56 +1906,56 @@ func (bc *Blockchain) getCachedBlockViewAndUtxoOps(blockHash BlockHash) (*BlockV
19061906
return nil, nil, false
19071907
}
19081908

1909-
// getUtxoViewAndUtxoOpsAtBlockHash builds a UtxoView to the block provided and returns a BlockViewAndUtxoOps
1909+
// GetUtxoViewAndUtxoOpsAtBlockHash builds a UtxoView to the block provided and returns a BlockViewAndUtxoOps
19101910
// struct containing UtxoView, the UtxoOperations that resulted from connecting the block, and the full
19111911
// block (MsgDeSoBlock) for convenience that came from connecting the block. It does this by identifying
19121912
// all uncommitted ancestors of this block. Then it checks the block view cache to see if we have already
19131913
// computed this view. If not, connecting the uncommitted ancestor blocks and saving to the cache. The
19141914
// returned UtxoOps and FullBlock should NOT be modified.
1915-
func (bc *Blockchain) getUtxoViewAndUtxoOpsAtBlockHash(blockHash BlockHash) (
1915+
func (bc *Blockchain) GetUtxoViewAndUtxoOpsAtBlockHash(blockHash BlockHash) (
19161916
*BlockViewAndUtxoOps, error) {
19171917
// Always fetch the lineage from the committed tip to the block provided first to
19181918
// ensure that a valid UtxoView is returned.
19191919
uncommittedAncestors := []*BlockNode{}
19201920
currentBlock, _ := bc.blockIndexByHash.Get(blockHash)
19211921
if currentBlock == nil {
1922-
return nil, errors.Errorf("getUtxoViewAndUtxoOpsAtBlockHash: Block %v not found in block index", blockHash)
1922+
return nil, errors.Errorf("GetUtxoViewAndUtxoOpsAtBlockHash: Block %v not found in block index", blockHash)
19231923
}
19241924

19251925
highestCommittedBlock, _ := bc.GetCommittedTip()
19261926
if highestCommittedBlock == nil {
1927-
return nil, errors.Errorf("getUtxoViewAndUtxoOpsAtBlockHash: No committed blocks found")
1927+
return nil, errors.Errorf("GetUtxoViewAndUtxoOpsAtBlockHash: No committed blocks found")
19281928
}
19291929
// If the provided block is committed, we need to make sure it's the committed tip.
19301930
// Otherwise, we return an error.
19311931
if currentBlock.IsCommitted() {
19321932
if !highestCommittedBlock.Hash.IsEqual(&blockHash) {
19331933
return nil, errors.Errorf(
1934-
"getUtxoViewAndUtxoOpsAtBlockHash: Block %v is committed but not the committed tip", blockHash)
1934+
"GetUtxoViewAndUtxoOpsAtBlockHash: Block %v is committed but not the committed tip", blockHash)
19351935
}
19361936
}
19371937
for !currentBlock.IsCommitted() {
19381938
uncommittedAncestors = append(uncommittedAncestors, currentBlock)
19391939
currentParentHash := currentBlock.Header.PrevBlockHash
19401940
if currentParentHash == nil {
1941-
return nil, errors.Errorf("getUtxoViewAndUtxoOpsAtBlockHash: Block %v has nil PrevBlockHash", currentBlock.Hash)
1941+
return nil, errors.Errorf("GetUtxoViewAndUtxoOpsAtBlockHash: Block %v has nil PrevBlockHash", currentBlock.Hash)
19421942
}
19431943
currentBlock, _ = bc.blockIndexByHash.Get(*currentParentHash)
19441944
if currentBlock == nil {
1945-
return nil, errors.Errorf("getUtxoViewAndUtxoOpsAtBlockHash: Block %v not found in block index", currentParentHash)
1945+
return nil, errors.Errorf("GetUtxoViewAndUtxoOpsAtBlockHash: Block %v not found in block index", currentParentHash)
19461946
}
19471947
if currentBlock.IsCommitted() && !currentBlock.Hash.IsEqual(highestCommittedBlock.Hash) {
19481948
return nil, errors.Errorf(
1949-
"getUtxoViewAndUtxoOpsAtBlockHash: extends from a committed block that isn't the committed tip")
1949+
"GetUtxoViewAndUtxoOpsAtBlockHash: extends from a committed block that isn't the committed tip")
19501950
}
19511951
if currentBlock.IsCommitted() && !currentBlock.Hash.IsEqual(highestCommittedBlock.Hash) {
19521952
return nil, errors.Errorf(
1953-
"getUtxoViewAndUtxoOpsAtBlockHash: extends from a committed block that isn't the committed tip")
1953+
"GetUtxoViewAndUtxoOpsAtBlockHash: extends from a committed block that isn't the committed tip")
19541954
}
19551955
}
19561956
viewAndUtxoOpsAtHash, err, exists := bc.getCachedBlockViewAndUtxoOps(blockHash)
19571957
if err != nil {
1958-
return nil, errors.Wrapf(err, "getUtxoViewAndUtxoOpsAtBlockHash: Problem getting cached BlockViewAndUtxoOps")
1958+
return nil, errors.Wrapf(err, "GetUtxoViewAndUtxoOpsAtBlockHash: Problem getting cached BlockViewAndUtxoOps")
19591959
}
19601960
if exists {
19611961
viewAndUtxoOpsCopy := viewAndUtxoOpsAtHash.Copy()

lib/pos_blockchain_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ func _generateRealBlockWithFailingTxn(testMeta *TestMeta, blockHeight uint64, vi
24642464
prevBlock, exists := testMeta.chain.blockIndexByHash.Get(*prevBlockHash)
24652465
require.True(testMeta.t, exists)
24662466
// Always update the testMeta latestBlockView
2467-
latestBlockViewAndUtxoOps, err := testMeta.chain.getUtxoViewAndUtxoOpsAtBlockHash(*prevBlockHash)
2467+
latestBlockViewAndUtxoOps, err := testMeta.chain.GetUtxoViewAndUtxoOpsAtBlockHash(*prevBlockHash)
24682468
require.NoError(testMeta.t, err)
24692469
latestBlockView := latestBlockViewAndUtxoOps.UtxoView
24702470
latestBlockNode, latestBlockNodeExists := testMeta.chain.blockIndexByHash.Get(*prevBlockHash)

lib/pos_consensus.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ func (fc *FastHotStuffConsensus) tryProcessBlockAsNewTip(block *MsgDeSoBlock) ([
693693
return nil, errors.Errorf("Error hashing tip block: %v", err)
694694
}
695695

696-
utxoViewAndUtxoOps, err := fc.blockchain.getUtxoViewAndUtxoOpsAtBlockHash(*tipBlockHash)
696+
utxoViewAndUtxoOps, err := fc.blockchain.GetUtxoViewAndUtxoOpsAtBlockHash(*tipBlockHash)
697697
if err != nil {
698698
return nil, errors.Errorf("Error fetching UtxoView for tip block: %v", err)
699699
}
@@ -739,7 +739,7 @@ func (fc *FastHotStuffConsensus) produceUnsignedBlockForBlockProposalEvent(
739739
}
740740

741741
// Build a UtxoView at the parent block
742-
parentUtxoViewAndUtxoOps, err := fc.blockchain.getUtxoViewAndUtxoOpsAtBlockHash(*parentBlockHash)
742+
parentUtxoViewAndUtxoOps, err := fc.blockchain.GetUtxoViewAndUtxoOpsAtBlockHash(*parentBlockHash)
743743
if err != nil {
744744
// This should never happen as long as the parent block is a descendant of the committed tip.
745745
return nil, errors.Errorf("Error fetching UtxoView for parent block: %v", parentBlockHash)

lib/state_change_syncer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ func (stateChangeSyncer *StateChangeSyncer) SyncMempoolToStateSyncer(server *Ser
847847
// TODO: Have Z look at if we need to do some caching in the uncommitted blocks logic.
848848
// First connect the uncommitted blocks to the mempool view.
849849
for _, uncommittedBlock := range uncommittedBlocks {
850-
utxoViewAndOpsAtBlockHash, err := server.blockchain.getUtxoViewAndUtxoOpsAtBlockHash(*uncommittedBlock.Hash)
850+
utxoViewAndOpsAtBlockHash, err := server.blockchain.GetUtxoViewAndUtxoOpsAtBlockHash(*uncommittedBlock.Hash)
851851
if err != nil {
852852
mempoolUtxoView.EventManager.stateSyncerFlushed(&StateSyncerFlushedEvent{
853853
FlushId: originalCommittedFlushId,

lib/txindex.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func (txi *TXIndex) Update() error {
408408
utxoView := NewUtxoView(txi.TXIndexChain.DB(), txi.Params, nil, nil, txi.CoreChain.eventManager)
409409
if blockToAttach.Header.PrevBlockHash != nil && !utxoView.TipHash.IsEqual(blockToAttach.Header.PrevBlockHash) {
410410
var utxoViewAndUtxoOps *BlockViewAndUtxoOps
411-
utxoViewAndUtxoOps, err = txi.TXIndexChain.getUtxoViewAndUtxoOpsAtBlockHash(*blockToAttach.Header.PrevBlockHash)
411+
utxoViewAndUtxoOps, err = txi.TXIndexChain.GetUtxoViewAndUtxoOpsAtBlockHash(*blockToAttach.Header.PrevBlockHash)
412412
if err != nil {
413413
return fmt.Errorf("Update: Problem getting UtxoView at block hash %v: %v",
414414
blockToAttach.Header.PrevBlockHash, err)

0 commit comments

Comments
 (0)