-
Notifications
You must be signed in to change notification settings - Fork 646
/
rejector.go
67 lines (54 loc) · 1.56 KB
/
rejector.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package executor
import (
"go.uber.org/zap"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/vms/platformvm/blocks"
)
var _ blocks.Visitor = &rejector{}
// rejector handles the logic for rejecting a block.
// All errors returned by this struct are fatal and should result in the chain
// being shutdown.
type rejector struct {
*backend
}
func (r *rejector) ProposalBlock(b *blocks.ProposalBlock) error {
return r.rejectBlock(b, "proposal")
}
func (r *rejector) AtomicBlock(b *blocks.AtomicBlock) error {
return r.rejectBlock(b, "atomic")
}
func (r *rejector) StandardBlock(b *blocks.StandardBlock) error {
return r.rejectBlock(b, "standard")
}
func (r *rejector) CommitBlock(b *blocks.CommitBlock) error {
return r.rejectBlock(b, "commit")
}
func (r *rejector) AbortBlock(b *blocks.AbortBlock) error {
return r.rejectBlock(b, "abort")
}
func (r *rejector) rejectBlock(b blocks.Block, blockType string) error {
blkID := b.ID()
r.ctx.Log.Verbo(
"rejecting block",
zap.String("blockType", blockType),
zap.Stringer("blkID", blkID),
zap.Uint64("height", b.Height()),
zap.Stringer("parentID", b.Parent()),
)
for _, tx := range b.Txs() {
if err := r.Mempool.Add(tx); err != nil {
r.ctx.Log.Debug(
"failed to reissue tx",
zap.Stringer("txID", tx.ID()),
zap.Stringer("blkID", blkID),
zap.Error(err),
)
}
}
r.state.AddStatelessBlock(b, choices.Rejected)
err := r.state.Commit()
r.free(blkID)
return err
}