forked from CyberMiles/travis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.go
101 lines (88 loc) · 2.5 KB
/
globals.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
package utils
import (
"github.com/ethereum/go-ethereum/common"
"math"
"math/big"
)
type StateChangeObject struct {
From common.Address
To common.Address
Amount *big.Int
Reactor StateChangeReactor
}
type StateChangeReactor interface {
React(result, msg string)
}
type pendingProposal struct {
proposals map[string]uint64
minExpireBlockHeight uint64
minHeightMappedPid []string
}
func (p *pendingProposal) BatchAdd(proposals map[string]uint64) {
p.proposals = proposals
p.update()
}
func (p *pendingProposal) Add(pid string, expireBlockHeight uint64) {
p.proposals[pid] = expireBlockHeight
if p.minExpireBlockHeight > expireBlockHeight {
p.minHeightMappedPid = []string{pid}
p.minExpireBlockHeight = expireBlockHeight
} else if p.minExpireBlockHeight == expireBlockHeight {
p.minHeightMappedPid = append(p.minHeightMappedPid, pid)
}
}
func (p *pendingProposal) Del(pid string) {
expireBlockHeight := p.proposals[pid]
delete(p.proposals, pid)
if p.minExpireBlockHeight == expireBlockHeight {
if len(p.minHeightMappedPid) == 1 {
p.update()
} else {
for idx, id := range p.minHeightMappedPid {
if id == pid {
p.minHeightMappedPid = append(p.minHeightMappedPid[:idx], p.minHeightMappedPid[idx+1:]...)
break
}
}
}
}
}
func (p *pendingProposal) update() {
min := uint64(math.MaxUint64)
for pid, bh := range p.proposals {
if min > bh {
min = bh
p.minHeightMappedPid = []string{pid}
} else if min == bh {
p.minHeightMappedPid = append(p.minHeightMappedPid, pid)
}
}
p.minExpireBlockHeight = min
}
func (p *pendingProposal) ReachMin(blockHeight uint64) (pids []string) {
if p.minExpireBlockHeight == blockHeight {
pids = p.minHeightMappedPid
for _, pid := range pids {
delete(p.proposals, pid)
}
p.update()
}
return
}
var (
BlockGasFee *big.Int
StateChangeQueue []StateChangeObject
// Recording addresses associated with travis tx (stake/governance) in one block
// Transfer transaction is not allowed if the sender of which was found in this recording
// TODO to be removed
TravisTxAddrs []*common.Address
NonceCheckedTx map[common.Hash]bool = make(map[common.Hash]bool)
PendingProposal = &pendingProposal{
make(map[string]uint64),
math.MaxUint64,
nil,
}
MintAccount = common.HexToAddress("0000000000000000000000000000000000000000")
HoldAccount = common.HexToAddress("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
GovHoldAccount = common.HexToAddress("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
)