forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
memory_block.go
34 lines (26 loc) · 898 Bytes
/
memory_block.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowman
import (
"context"
"github.com/MetalBlockchain/metalgo/snow/consensus/snowman"
)
var _ snowman.Block = (*memoryBlock)(nil)
// memoryBlock wraps a snowman Block to manage non-verified blocks
type memoryBlock struct {
snowman.Block
tree AncestorTree
metrics *metrics
}
// Accept accepts the underlying block & removes sibling subtrees
func (mb *memoryBlock) Accept(ctx context.Context) error {
mb.tree.RemoveSubtree(mb.Parent())
mb.metrics.numNonVerifieds.Set(float64(mb.tree.Len()))
return mb.Block.Accept(ctx)
}
// Reject rejects the underlying block & removes child subtrees
func (mb *memoryBlock) Reject(ctx context.Context) error {
mb.tree.RemoveSubtree(mb.ID())
mb.metrics.numNonVerifieds.Set(float64(mb.tree.Len()))
return mb.Block.Reject(ctx)
}