Skip to content

Commit

Permalink
Transfer changes from z/update-state-change-entry-encoder to pos
Browse files Browse the repository at this point in the history
  • Loading branch information
lazynina committed Apr 18, 2024
1 parent 32c097a commit 26186dc
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 129 deletions.
26 changes: 17 additions & 9 deletions lib/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2558,17 +2558,15 @@ func (bc *Blockchain) processBlockPoW(desoBlock *MsgDeSoBlock, verifySignatures
}
bc.timer.End("Blockchain.ProcessBlock: Transactions Db snapshot & operations")
if innerErr = bc.blockView.FlushToDbWithTxn(txn, blockHeight); innerErr != nil {
// If we're in the middle of a sync, we should notify the event manager that we failed to sync the block.
if bc.eventManager != nil && !bc.eventManager.isMempoolManager {
bc.eventManager.stateSyncerFlushed(&StateSyncerFlushedEvent{
FlushId: uuid.Nil,
Succeeded: false,
})
}
return errors.Wrapf(innerErr, "ProcessBlock: Problem writing utxo view to db on simple add to tip")
}
// Immediately after the utxo view is flushed to badger, emit a state syncer flushed event, so that
// state syncer maintains a consistent view of the blockchain.
// Note: We ignore the mempool manager here, as that process handles state syncer flush events itself.
if bc.eventManager != nil && !bc.eventManager.isMempoolManager {
bc.eventManager.stateSyncerFlushed(&StateSyncerFlushedEvent{
FlushId: uuid.Nil,
Succeeded: innerErr == nil,
})
}

bc.timer.End("Blockchain.ProcessBlock: Transactions Db utxo flush")
bc.timer.Start("Blockchain.ProcessBlock: Transactions Db snapshot & operations")
Expand Down Expand Up @@ -2927,6 +2925,16 @@ func (bc *Blockchain) processBlockPoW(desoBlock *MsgDeSoBlock, verifySignatures
// Signal the server that we've accepted this block in some way.
if bc.eventManager != nil {
bc.eventManager.blockAccepted(&BlockEvent{Block: desoBlock})
// Immediately after the utxo view is flushed to badger, emit a state syncer flushed event, so that
// state syncer maintains a consistent view of the blockchain.
// Note: We ignore the mempool manager here, as that process handles state syncer flush events itself.
if !bc.eventManager.isMempoolManager {
fmt.Printf("Emitting state syncer flushed event for synced block\n")
bc.eventManager.stateSyncerFlushed(&StateSyncerFlushedEvent{
FlushId: uuid.Nil,
Succeeded: true,
})
}
}

bc.timer.Print("Blockchain.ProcessBlock: Initial")
Expand Down
4 changes: 3 additions & 1 deletion lib/db_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ type DBPrefixes struct {
// The Minor/Major distinction is used to deterministically map the two accessGroupIds of message's sender/recipient
// into a single pair based on the lexicographical ordering of the two accessGroupIds. This is done to ensure that
// both sides of the conversation have the same key for the same conversation, and we can store just a single message.
PrefixDmMessagesIndex []byte `prefix_id:"[75]" is_state:"true"`
PrefixDmMessagesIndex []byte `prefix_id:"[75]" is_state:"true" core_state:"true"`

// PrefixDmThreadIndex is modified by the NewMessage transaction and is used to store a DmThreadEntry
// for each existing dm thread. It answers the question: "Give me all the threads for a particular user."
Expand Down Expand Up @@ -1149,6 +1149,7 @@ func DBSetWithTxn(txn *badger.Txn, snap *Snapshot, key []byte, value []byte, eve
KeyBytes: key,
EncoderBytes: value,
AncestralRecordBytes: ancestralValue,
IsReverted: false,
},
FlushId: uuid.Nil,
IsMempoolTxn: eventManager.isMempoolManager,
Expand Down Expand Up @@ -1251,6 +1252,7 @@ func DBDeleteWithTxn(txn *badger.Txn, snap *Snapshot, key []byte, eventManager *
KeyBytes: key,
EncoderBytes: nil,
AncestralRecordBytes: ancestralValue,
IsReverted: false,
},
FlushId: uuid.Nil,
IsMempoolTxn: eventManager.isMempoolManager,
Expand Down
6 changes: 3 additions & 3 deletions lib/pos_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,9 @@ func (bc *Blockchain) commitBlockPoS(blockHash *BlockHash, verifySignatures bool
return errors.Wrapf(err, "commitBlockPoS: Problem putting block in db: ")
}

if bc.snapshot != nil {
bc.snapshot.FinishProcessBlock(blockNode)
}
if bc.eventManager != nil {
bc.eventManager.blockCommitted(&BlockEvent{
Block: block,
Expand All @@ -1741,9 +1744,6 @@ func (bc *Blockchain) commitBlockPoS(blockHash *BlockHash, verifySignatures bool
})
}
}
if bc.snapshot != nil {
bc.snapshot.FinishProcessBlock(blockNode)
}
currentEpochNumber, err := utxoView.GetCurrentEpochNumber()
if err != nil {
return errors.Wrapf(err, "commitBlockPoS: Problem getting current epoch number")
Expand Down
1 change: 1 addition & 0 deletions lib/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@ func (snap *Snapshot) SetSnapshotChunk(mainDb *badger.DB, mainDbMutex *deadlock.
OperationType: DbOperationTypeInsert,
KeyBytes: dbEntry.Key,
EncoderBytes: dbEntry.Value,
IsReverted: false,
},
FlushId: dbFlushId,
})
Expand Down
Loading

0 comments on commit 26186dc

Please sign in to comment.