Skip to content

Commit

Permalink
added error check for updating meta state
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 committed Apr 24, 2024
1 parent 0078764 commit d38a478
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
9 changes: 6 additions & 3 deletions process/blocksPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func (bp *blocksPool) Get(key []byte) ([]byte, error) {
return bp.storer.Get(key)
}

func (bp *blocksPool) UpdateMetaState(checkpoint *data.BlockCheckpoint) {
// UpdateMetaState will update internal meta state
func (bp *blocksPool) UpdateMetaState(checkpoint *data.BlockCheckpoint) error {
index, ok := checkpoint.LastRounds[core.MetachainShardId]
if !ok {
index = initIndex
Expand All @@ -89,14 +90,16 @@ func (bp *blocksPool) UpdateMetaState(checkpoint *data.BlockCheckpoint) {
if index >= bp.firstCommitableBlock {
err := bp.setCheckpoint(checkpoint)
if err != nil {
log.Warn("failed to set checkpoint", "error", err.Error())
return fmt.Errorf("%w, failed to set checkpoint", err)
}
}

err := bp.pruneStorer(index)
if err != nil {
log.Warn("failed to prune storer", "error", err.Error())
return fmt.Errorf("%w, failed to prune storer", err)
}

return nil
}

func (bp *blocksPool) pruneStorer(index uint64) error {
Expand Down
22 changes: 16 additions & 6 deletions process/dataProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ func (dp *dataProcessor) saveBlock(marshalledData []byte) error {
return ErrNilOutportBlockData
}

log.Info("saving block", "hash", outportBlock.BlockData.GetHeaderHash(), "shardID", outportBlock.ShardID)

if outportBlock.ShardID == core.MetachainShardId {
return dp.handleMetaOutportBlock(outportBlock)
}
Expand All @@ -105,6 +103,11 @@ func (dp *dataProcessor) handleMetaOutportBlock(outportBlock *outport.OutportBlo
}
metaRound := metaOutportBlock.BlockData.Header.GetRound()

log.Info("saving meta outport block",
"hash", metaOutportBlock.BlockData.GetHeaderHash(),
"round", metaRound,
"shardID", metaOutportBlock.ShardID)

headerHash := outportBlock.BlockData.HeaderHash
err = dp.outportBlocksPool.PutMetaBlock(headerHash, metaOutportBlock)
if err != nil {
Expand All @@ -122,7 +125,10 @@ func (dp *dataProcessor) handleMetaOutportBlock(outportBlock *outport.OutportBlo
core.MetachainShardId: metaRound,
},
}
dp.outportBlocksPool.UpdateMetaState(lastCheckpoint)
err = dp.outportBlocksPool.UpdateMetaState(lastCheckpoint)
if err != nil {
return err
}

return nil
}
Expand All @@ -142,9 +148,7 @@ func (dp *dataProcessor) handleMetaOutportBlock(outportBlock *outport.OutportBlo
return err
}

dp.outportBlocksPool.UpdateMetaState(lastCheckpoint)

return nil
return dp.outportBlocksPool.UpdateMetaState(lastCheckpoint)
}

// TODO: update to use latest data structures
Expand Down Expand Up @@ -175,6 +179,12 @@ func (dp *dataProcessor) handleShardOutportBlock(outportBlock *outport.OutportBl
if shardOutportBlock.BlockData.Header == nil {
return fmt.Errorf("%w for blockData header", ErrInvalidOutportBlock)
}
round := shardOutportBlock.BlockData.Header.GetRound()

log.Info("saving shard outport block",
"hash", shardOutportBlock.BlockData.GetHeaderHash(),
"round", round,
"shardID", shardOutportBlock.ShardID)

headerHash := outportBlock.BlockData.HeaderHash

Expand Down
4 changes: 2 additions & 2 deletions process/hyperBlocksPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func NewHyperOutportBlocksPool(
}

// UpdateMetaState will triiger meta state update from base data pool
func (bp *hyperOutportBlocksPool) UpdateMetaState(checkpoint *data.BlockCheckpoint) {
bp.dataPool.UpdateMetaState(checkpoint)
func (bp *hyperOutportBlocksPool) UpdateMetaState(checkpoint *data.BlockCheckpoint) error {
return bp.dataPool.UpdateMetaState(checkpoint)
}

// Get will trigger data pool get operation
Expand Down
4 changes: 2 additions & 2 deletions process/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type DataPool interface {
Put(key []byte, value []byte) error
Get(key []byte) ([]byte, error)
PutBlock(hash []byte, value []byte, round uint64, shardID uint32) error
UpdateMetaState(checkpoint *data.BlockCheckpoint)
UpdateMetaState(checkpoint *data.BlockCheckpoint) error
Close() error
IsInterfaceNil() bool
}
Expand All @@ -74,7 +74,7 @@ type HyperBlocksPool interface {
PutShardBlock(hash []byte, outportBlock *hyperOutportBlocks.ShardOutportBlock) error
GetMetaBlock(hash []byte) (*hyperOutportBlocks.MetaOutportBlock, error)
GetShardBlock(hash []byte) (*hyperOutportBlocks.ShardOutportBlock, error)
UpdateMetaState(checkpoint *data.BlockCheckpoint)
UpdateMetaState(checkpoint *data.BlockCheckpoint) error
Close() error
IsInterfaceNil() bool
}
Expand Down

0 comments on commit d38a478

Please sign in to comment.