github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/snowman/memory_block.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package snowman 5 6 import ( 7 "context" 8 9 "github.com/MetalBlockchain/metalgo/snow/consensus/snowman" 10 "github.com/MetalBlockchain/metalgo/snow/engine/snowman/ancestor" 11 ) 12 13 var _ snowman.Block = (*memoryBlock)(nil) 14 15 // memoryBlock wraps a snowman Block to manage non-verified blocks 16 type memoryBlock struct { 17 snowman.Block 18 19 tree ancestor.Tree 20 metrics *metrics 21 } 22 23 // Accept accepts the underlying block & removes sibling subtrees 24 func (mb *memoryBlock) Accept(ctx context.Context) error { 25 mb.tree.RemoveDescendants(mb.Parent()) 26 mb.metrics.numNonVerifieds.Set(float64(mb.tree.Len())) 27 return mb.Block.Accept(ctx) 28 } 29 30 // Reject rejects the underlying block & removes child subtrees 31 func (mb *memoryBlock) Reject(ctx context.Context) error { 32 mb.tree.RemoveDescendants(mb.ID()) 33 mb.metrics.numNonVerifieds.Set(float64(mb.tree.Len())) 34 return mb.Block.Reject(ctx) 35 }