-
Notifications
You must be signed in to change notification settings - Fork 660
/
tx_mempool_verifier.go
130 lines (106 loc) · 3.29 KB
/
tx_mempool_verifier.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package executor
import (
"errors"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/platformvm/state"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)
var _ txs.Visitor = &MempoolTxVerifier{}
type MempoolTxVerifier struct {
*Backend
ParentID ids.ID
StateVersions state.Versions
Tx *txs.Tx
}
func (*MempoolTxVerifier) AdvanceTimeTx(*txs.AdvanceTimeTx) error { return errWrongTxType }
func (*MempoolTxVerifier) RewardValidatorTx(*txs.RewardValidatorTx) error { return errWrongTxType }
func (v *MempoolTxVerifier) AddValidatorTx(tx *txs.AddValidatorTx) error {
return v.proposalTx(tx)
}
func (v *MempoolTxVerifier) AddSubnetValidatorTx(tx *txs.AddSubnetValidatorTx) error {
return v.proposalTx(tx)
}
func (v *MempoolTxVerifier) AddDelegatorTx(tx *txs.AddDelegatorTx) error {
return v.proposalTx(tx)
}
func (v *MempoolTxVerifier) CreateChainTx(tx *txs.CreateChainTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) CreateSubnetTx(tx *txs.CreateSubnetTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) ImportTx(tx *txs.ImportTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) ExportTx(tx *txs.ExportTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) RemoveSubnetValidatorTx(tx *txs.RemoveSubnetValidatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) TransformSubnetTx(tx *txs.TransformSubnetTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) AddPermissionlessValidatorTx(tx *txs.AddPermissionlessValidatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) AddPermissionlessDelegatorTx(tx *txs.AddPermissionlessDelegatorTx) error {
return v.standardTx(tx)
}
// TODO: simplify this function after Blueberry is activated.
func (v *MempoolTxVerifier) proposalTx(tx txs.StakerTx) error {
startTime := tx.StartTime()
maxLocalStartTime := v.Clk.Time().Add(MaxFutureStartTime)
if startTime.After(maxLocalStartTime) {
return errFutureStakeTime
}
onCommitState, err := state.NewDiff(v.ParentID, v.StateVersions)
if err != nil {
return err
}
// Make sure that the Blueberry fork check will pass.
currentChainTime := onCommitState.GetTimestamp()
if v.Backend.Config.IsBlueberryActivated(currentChainTime) {
return v.standardTx(tx)
}
onAbortState, err := state.NewDiff(v.ParentID, v.StateVersions)
if err != nil {
return err
}
executor := ProposalTxExecutor{
OnCommitState: onCommitState,
OnAbortState: onAbortState,
Backend: v.Backend,
Tx: v.Tx,
}
err = tx.Visit(&executor)
// We ignore [errFutureStakeTime] here because the time will be advanced
// when this transaction is issued.
if errors.Is(err, errFutureStakeTime) {
return nil
}
return err
}
func (v *MempoolTxVerifier) standardTx(tx txs.UnsignedTx) error {
state, err := state.NewDiff(
v.ParentID,
v.StateVersions,
)
if err != nil {
return err
}
executor := StandardTxExecutor{
Backend: v.Backend,
State: state,
Tx: v.Tx,
}
err = tx.Visit(&executor)
// We ignore [errFutureStakeTime] here because the time will be advanced
// when this transaction is issued.
if errors.Is(err, errFutureStakeTime) {
return nil
}
return err
}