forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tx_job.go
62 lines (54 loc) · 1.36 KB
/
tx_job.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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package avalanche
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow/choices"
"github.com/ava-labs/gecko/snow/consensus/snowstorm"
"github.com/ava-labs/gecko/snow/engine/common/queue"
)
type txParser struct {
numAccepted, numDropped prometheus.Counter
vm DAGVM
}
func (p *txParser) Parse(txBytes []byte) (queue.Job, error) {
tx, err := p.vm.ParseTx(txBytes)
if err != nil {
return nil, err
}
return &txJob{
numAccepted: p.numAccepted,
numDropped: p.numDropped,
tx: tx,
}, nil
}
type txJob struct {
numAccepted, numDropped prometheus.Counter
tx snowstorm.Tx
}
func (t *txJob) ID() ids.ID { return t.tx.ID() }
func (t *txJob) MissingDependencies() ids.Set {
missing := ids.Set{}
for _, dep := range t.tx.Dependencies() {
if dep.Status() != choices.Accepted {
missing.Add(dep.ID())
}
}
return missing
}
func (t *txJob) Execute() {
if t.MissingDependencies().Len() != 0 {
t.numDropped.Inc()
return
}
switch t.tx.Status() {
case choices.Unknown, choices.Rejected:
t.numDropped.Inc()
case choices.Processing:
t.tx.Verify()
t.tx.Accept()
t.numAccepted.Inc()
}
}
func (t *txJob) Bytes() []byte { return t.tx.Bytes() }