Skip to content

Commit

Permalink
add parent id for snow block
Browse files Browse the repository at this point in the history
  • Loading branch information
bysomeone committed May 16, 2024
1 parent 48ac907 commit d67a164
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions system/consensus/snowman/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
// wrap chain33 block for implementing the snowman.Block interface
type snowBlock struct {
id ids.ID
parent ids.ID
block *types.Block
status choices.Status
vm *chain33VM
Expand All @@ -25,7 +26,7 @@ func (b *snowBlock) ID() ids.ID { return b.id }
func (b *snowBlock) Accept(ctx context.Context) error {

b.status = choices.Accepted
snowLog.Debug("snowBlock accept", "hash", b.id.Hex(), "height", b.Height())
snowLog.Debug("snowBlock accept", "hash", b.id.Hex(), "height", b.Height(), "parent", b.Parent().Hex())
err := b.vm.acceptBlock(b.block.Height, b.id)
if err != nil {
snowLog.Error("Accepting block error", "hash", b.id.Hex(), "height", b.Height())
Expand All @@ -37,7 +38,7 @@ func (b *snowBlock) Accept(ctx context.Context) error {
// This element will not be accepted by any correct node in the network.
func (b *snowBlock) Reject(ctx context.Context) error {
b.status = choices.Rejected
snowLog.Debug("snowBlock reject", "hash", b.ID().Hex(), "height", b.Height())
snowLog.Debug("snowBlock reject", "hash", b.ID().Hex(), "height", b.Height(), "parent", b.Parent().Hex())
b.vm.rejectBlock(b.block.Height, b.ID())
return nil
}
Expand All @@ -53,7 +54,7 @@ func (b *snowBlock) Status() choices.Status {

// Parent implements the snowman.Block interface
func (b *snowBlock) Parent() ids.ID {
return toSnowID(b.block.ParentHash)
return b.parent
}

// Height implements the snowman.Block interface
Expand Down
6 changes: 4 additions & 2 deletions system/consensus/snowman/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (vm *chain33VM) newSnowBlock(blk *types.Block, status choices.Status) *snow

sb := &snowBlock{block: blk, vm: vm, status: status}
sb.id = toSnowID(blk.Hash(vm.cfg))
sb.parent = toSnowID(blk.GetParentHash())
return sb
}

Expand Down Expand Up @@ -159,7 +160,7 @@ func (vm *chain33VM) addNewBlock(blk *types.Block) bool {
defer vm.lock.Unlock()
vm.pendingBlocks.PushBack(vm.newSnowBlock(blk, choices.Processing))
snowLog.Debug("vm addNewBlock", "height", blk.GetHeight(), "hash", hex.EncodeToString(blk.Hash(vm.cfg)),
"acceptedHeight", ah, "pendingNum", vm.pendingBlocks.Len())
"parent", hex.EncodeToString(blk.ParentHash), "acceptedHeight", ah, "pendingNum", vm.pendingBlocks.Len())
return true
}

Expand All @@ -178,7 +179,8 @@ func (vm *chain33VM) BuildBlock(_ context.Context) (snowcon.Block, error) {
if sb.Height() <= uint64(ah) {
continue
}
snowLog.Debug("vmBuildBlock", "pendingNum", vm.pendingBlocks.Len(), "height", sb.Height(), "hash", sb.id.Hex())
snowLog.Debug("vmBuildBlock", "pendingNum", vm.pendingBlocks.Len(), "height", sb.Height(),
"hash", sb.id.Hex(), "parent", sb.Parent().Hex())
return sb, nil
}

Expand Down

0 comments on commit d67a164

Please sign in to comment.