Skip to content

Commit 429c244

Browse files
authored
Merge pull request #655 from vitelabs/release_v2.14.0
Release v2.14.0
2 parents aa1cadd + 86456f0 commit 429c244

14 files changed

+128
-73
lines changed

.github/workflows/dispatch-nightly-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-18.04
11+
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v2
1414
- name: Read buildversion

.github/workflows/nightly-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
build:
12-
runs-on: ubuntu-18.04
12+
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
1515
with:

.github/workflows/release-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
build:
15-
runs-on: ubuntu-18.04
15+
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v2
1818
with:

common/upgrade/face.go

+18-13
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ func GetAllPoints() []*UpgradePoint {
8888
IsSeedUpgrade checks whether current snapshot block height is over seed hard fork.
8989
Vite pre-mainnet hard forks at snapshot block height 3488471.
9090
Contents:
91-
1. Vm log list hash add account address and prevHash since seed fork.
92-
2. Create contract params add seed count since seed fork.
93-
3. Verifier verifies seed count since seed fork.
94-
4. Vm interpreters add SEED opcode since seed fork.
91+
1. Vm log list hash add account address and prevHash since seed fork.
92+
2. Create contract params add seed count since seed fork.
93+
3. Verifier verifies seed count since seed fork.
94+
4. Vm interpreters add SEED opcode since seed fork.
9595
*/
9696
func IsSeedUpgrade(sHeight uint64) bool {
9797
assertUpgradeNotNil()
@@ -102,11 +102,11 @@ func IsSeedUpgrade(sHeight uint64) bool {
102102
IsDexUpgrade checks whether current snapshot block height is over sprout hard fork.
103103
Vite pre-mainnet hard forks at snapshot block height 5442723.
104104
Features:
105-
1. Dynamic quota acquisition. Quota acquisition from staking will reduce
106-
when network traffic rate is too high.
107-
2. Adjustment of quota consumption for some built-in contract transactions
108-
and VM instructions.
109-
3. ViteX decentralized exchange support.
105+
1. Dynamic quota acquisition. Quota acquisition from staking will reduce
106+
when network traffic rate is too high.
107+
2. Adjustment of quota consumption for some built-in contract transactions
108+
and VM instructions.
109+
3. ViteX decentralized exchange support.
110110
*/
111111
func IsDexUpgrade(sHeight uint64) bool {
112112
assertUpgradeNotNil()
@@ -128,9 +128,9 @@ func IsDexFeeUpgrade(sHeight uint64) bool {
128128
IsStemUpgrade checks whether current snapshot block height is over stem hard fork.
129129
Vite pre-mainnet hard forks at snapshot block height 8403110.
130130
Features:
131-
1. Capability of placing/cancelling orders via delegation.
132-
2. Super VIP membership. Stake and then enjoy zero trading fee!
133-
(Additional operator fee cannot be exempted)
131+
1. Capability of placing/cancelling orders via delegation.
132+
2. Super VIP membership. Stake and then enjoy zero trading fee!
133+
(Additional operator fee cannot be exempted)
134134
*/
135135
func IsStemUpgrade(sHeight uint64) bool {
136136
assertUpgradeNotNil()
@@ -181,7 +181,12 @@ func IsVersion12Upgrade(sHeight uint64) bool {
181181
return upgrade.isActive(12, sHeight)
182182
}
183183

184-
func IsVersionXUpgrade(sHeight uint64) bool {
184+
func IsVersion13Upgrade(sHeight uint64) bool {
185185
assertUpgradeNotNil()
186186
return upgrade.isActive(13, sHeight)
187187
}
188+
189+
func IsVersionXUpgrade(sHeight uint64) bool {
190+
assertUpgradeNotNil()
191+
return upgrade.isActive(14, sHeight)
192+
}

common/upgrade/upgrade_init.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func NewLatestUpgradeBox() *upgradeBox {
5555
Height: 1,
5656
Version: 13,
5757
},
58+
{
59+
Height: 1,
60+
Version: 14,
61+
},
5862
})
5963
}
6064

@@ -120,10 +124,15 @@ func NewMainnetUpgradeBox() *upgradeBox {
120124
Height: 116480000,
121125
Version: 12,
122126
},
127+
{
128+
Name: "Version13",
129+
Height: 166869900,
130+
Version: 13,
131+
},
123132
{
124133
Name: "VersionX",
125134
Height: EndlessHeight,
126-
Version: 13,
135+
Version: 14,
127136
},
128137
})
129138
}

common/upgrade/upgrade_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func TestMainnetUpgradeBox(t *testing.T) {
7676
IsVersion12Upgrade,
7777
116480000,
7878
},
79+
{
80+
IsVersion13Upgrade,
81+
166869900,
82+
},
7983
{
8084
IsVersionXUpgrade,
8185
EndlessHeight,
@@ -84,7 +88,7 @@ func TestMainnetUpgradeBox(t *testing.T) {
8488
for _, ele := range cases {
8589
testUpgradePoint(t, ele.fc, ele.sHeight)
8690
}
87-
assert.Equal(t, (int)(GetLatestPoint().Version), 12)
91+
assert.Equal(t, (int)(GetLatestPoint().Version), 13)
8892
}
8993

9094
func TestLatestUpgradeBox(t *testing.T) {
@@ -144,6 +148,10 @@ func TestLatestUpgradeBox(t *testing.T) {
144148
IsVersion12Upgrade,
145149
1,
146150
},
151+
{
152+
IsVersion13Upgrade,
153+
1,
154+
},
147155
{
148156
IsVersionXUpgrade,
149157
1,

ledger/pool/account_pool.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func (accB *accountPoolBlock) Owner() *types.Address {
9090
return &accB.block.AccountAddress
9191
}
9292

93+
func (accB accountPoolBlock) Ready() bool {
94+
return true
95+
}
96+
9397
func newAccountPool(name string, rw *accountCh, v *common.Version, hashBlacklist Blacklist, log log15.Logger) *accountPool {
9498
pool := &accountPool{}
9599
pool.ID = name
@@ -109,11 +113,12 @@ func (accP *accountPool) Init(
109113
accP.BCPool.init(tools)
110114
}
111115

112-
/**
113-
1. compact for data
114-
1.1. free blocks
115-
1.2. snippet chain
116-
2. fetch block for snippet chain.
116+
/*
117+
*
118+
1. compact for data
119+
1.1. free blocks
120+
1.2. snippet chain
121+
2. fetch block for snippet chain.
117122
*/
118123
func (accP *accountPool) Compact() int {
119124
accP.chainHeadMu.Lock()
@@ -124,7 +129,7 @@ func (accP *accountPool) Compact() int {
124129

125130
defer monitor.LogTime("pool", "accountSnippet", now)
126131
accP.loopTime = now
127-
sum = sum + accP.loopGenSnippetChains()
132+
sum = sum + accP.loopGenSnippetChains(false)
128133
sum = sum + accP.loopAppendChains()
129134

130135
if now.After(accP.loopFetchTime.Add(time.Millisecond * 200)) {
@@ -137,7 +142,8 @@ func (accP *accountPool) Compact() int {
137142
return sum
138143
}
139144

140-
/**
145+
/*
146+
*
141147
try insert block to real chain.
142148
*/
143149
func (accP *accountPool) pendingAccountTo(h *ledger.HashHeight, sHeight uint64) (*ledger.HashHeight, error) {

ledger/pool/bc_pool.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func (a ByTailHeight) Len() int { return len(a) }
329329
func (a ByTailHeight) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
330330
func (a ByTailHeight) Less(i, j int) bool { return a[i].tailHeight < a[j].tailHeight }
331331

332-
func (bcp *BCPool) loopGenSnippetChains() int {
332+
func (bcp *BCPool) loopGenSnippetChains(readyFilter bool) int {
333333
if len(bcp.blockpool.freeBlocks) == 0 {
334334
return 0
335335
}
@@ -343,6 +343,11 @@ func (bcp *BCPool) loopGenSnippetChains() int {
343343
chains := copyMap(bcp.chainpool.snippetChains)
344344

345345
for _, v := range sortPending {
346+
if readyFilter {
347+
if !v.Ready() {
348+
continue
349+
}
350+
}
346351
if !tryInsert(chains, v) {
347352
snippet := newSnippetChain(v, bcp.chainpool.genChainID())
348353
chains = append(chains, snippet)
@@ -504,7 +509,7 @@ func (bcp *BCPool) CurrentChain() tree.Branch {
504509

505510
func (bcp *BCPool) loop() {
506511
for {
507-
bcp.loopGenSnippetChains()
512+
bcp.loopGenSnippetChains(false)
508513
bcp.loopAppendChains()
509514
bcp.loopFetchForSnippets()
510515
time.Sleep(time.Second)

ledger/pool/mock_common_block.go

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func (*mockCommonBlock) ReferHashes() ([]types.Hash, []types.Hash, *types.Hash)
9595
panic("implement me")
9696
}
9797

98+
func (mockCommonBlock) Ready() bool {
99+
return true
100+
}
101+
98102
func (m mockCommonBlock) computeHash() types.Hash {
99103
var source []byte
100104
// PrevHash

ledger/pool/pool.go

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type commonBlock interface {
8989
Latency() time.Duration
9090
ShouldFetch() bool
9191
ReferHashes() ([]types.Hash, []types.Hash, *types.Hash)
92+
Ready() bool
9293
}
9394

9495
func newForkBlock(v *common.Version, source types.BlockSource) *forkBlock {

ledger/pool/snapshot_pool.go

+53-43
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/vitelabs/go-vite/v2/common"
1111
"github.com/vitelabs/go-vite/v2/common/types"
12+
"github.com/vitelabs/go-vite/v2/common/upgrade"
1213
ledger "github.com/vitelabs/go-vite/v2/interfaces/core"
1314
"github.com/vitelabs/go-vite/v2/ledger/pool/batch"
1415
"github.com/vitelabs/go-vite/v2/ledger/pool/tree"
@@ -78,6 +79,14 @@ func (sb *snapshotPoolBlock) Owner() *types.Address {
7879
return nil
7980
}
8081

82+
func (sb snapshotPoolBlock) Ready() bool {
83+
// If a block comes from the future with a maximum error of one second, then it is illegal.
84+
if sb.block.Timestamp.After(time.Now().Add(time.Second)) {
85+
return false
86+
}
87+
return true
88+
}
89+
8190
func newSnapshotPool(
8291
name string,
8392
version *common.Version,
@@ -218,7 +227,8 @@ func (sp *snapshotPool) loopCompactSnapshot() int {
218227
sp.chainHeadMu.Lock()
219228
defer sp.chainHeadMu.Unlock()
220229
sum := 0
221-
sp.loopGenSnippetChains()
230+
// Starting from version 13, consider whether the block is ready when filtering.
231+
sp.loopGenSnippetChains(upgrade.IsVersion13Upgrade(sp.rw.headSnapshot().Height))
222232
sum += sp.loopAppendChains()
223233
now := time.Now()
224234
if now.After(sp.nextFetchTime) {
@@ -343,49 +353,49 @@ func (sp *snapshotPool) loopFetchForSnapshot() {
343353
return
344354
}
345355

346-
//func (self *snapshotPool) makeQueue(q Package, info *offsetInfo) (uint64, error) {
347-
// self.pool.RLock()
348-
// defer self.pool.RUnLock()
349-
// self.rMu.Lock()
350-
// defer self.rMu.Unlock()
356+
// func (self *snapshotPool) makeQueue(q Package, info *offsetInfo) (uint64, error) {
357+
// self.pool.RLock()
358+
// defer self.pool.RUnLock()
359+
// self.rMu.Lock()
360+
// defer self.rMu.Unlock()
351361
//
352-
// cp := self.chainpool
353-
// current := cp.current
362+
// cp := self.chainpool
363+
// current := cp.current
354364
//
355-
// if info.offset == nil {
356-
// info.offset = &ledger.HashHeight{Hash: current.tailHash, Height: current.tailHeight}
357-
// } else {
358-
// block := current.getBlock(info.offset.Height+1, false)
359-
// if block == nil || block.PrevHash() != info.offset.Hash {
360-
// return uint64(0), errors.New("current chain modify.")
365+
// if info.offset == nil {
366+
// info.offset = &ledger.HashHeight{Hash: current.tailHash, Height: current.tailHeight}
367+
// } else {
368+
// block := current.getBlock(info.offset.Height+1, false)
369+
// if block == nil || block.PrevHash() != info.offset.Hash {
370+
// return uint64(0), errors.New("current chain modify.")
371+
// }
361372
// }
362-
// }
363373
//
364-
// minH := info.offset.Height + 1
365-
// headH := current.headHeight
366-
// for i := minH; i <= headH; i++ {
367-
// block := self.getCurrentBlock(i)
368-
// if block == nil {
369-
// return uint64(i - minH), errors.New("current chain modify")
370-
// }
374+
// minH := info.offset.Height + 1
375+
// headH := current.headHeight
376+
// for i := minH; i <= headH; i++ {
377+
// block := self.getCurrentBlock(i)
378+
// if block == nil {
379+
// return uint64(i - minH), errors.New("current chain modify")
380+
// }
371381
//
372-
// if self.hashBlacklist.Exists(block.Hash()) {
373-
// return uint64(i - minH), errors.New("block in blacklist")
374-
// }
382+
// if self.hashBlacklist.Exists(block.Hash()) {
383+
// return uint64(i - minH), errors.New("block in blacklist")
384+
// }
375385
//
376-
// item := NewItem(block, nil)
386+
// item := NewItem(block, nil)
377387
//
378-
// err := q.AddItem(item)
379-
// if err != nil {
380-
// return uint64(i - minH), err
388+
// err := q.AddItem(item)
389+
// if err != nil {
390+
// return uint64(i - minH), err
391+
// }
392+
// info.offset.Hash = item.Hash()
393+
// info.offset.Height = item.Height()
381394
// }
382-
// info.offset.Hash = item.Hash()
383-
// info.offset.Height = item.Height()
384-
// }
385395
//
386-
// return uint64(headH - minH), errors.New("all in")
396+
// return uint64(headH - minH), errors.New("all in")
387397
//
388-
//}
398+
// }
389399
func (sp *snapshotPool) getCurrentBlock(i uint64) *snapshotPoolBlock {
390400
b := sp.CurrentChain().GetKnot(i, false)
391401
if b != nil {
@@ -394,16 +404,16 @@ func (sp *snapshotPool) getCurrentBlock(i uint64) *snapshotPoolBlock {
394404
return nil
395405
}
396406

397-
//func (self *snapshotPool) getPendingForCurrent() ([]commonBlock, error) {
398-
// begin := self.chainpool.current.tailHeight + 1
399-
// blocks := self.chainpool.getCurrentBlocks(begin, begin+10)
400-
// err := self.checkChain(blocks)
401-
// if err != nil {
402-
// return nil, err
403-
// }
407+
// func (self *snapshotPool) getPendingForCurrent() ([]commonBlock, error) {
408+
// begin := self.chainpool.current.tailHeight + 1
409+
// blocks := self.chainpool.getCurrentBlocks(begin, begin+10)
410+
// err := self.checkChain(blocks)
411+
// if err != nil {
412+
// return nil, err
413+
// }
404414
//
405-
// return blocks, nil
406-
//}
415+
// return blocks, nil
416+
// }
407417
func (sp *snapshotPool) fetchAccounts(accounts map[types.Address]*ledger.HashHeight, sHeight uint64, sHash types.Hash) {
408418
for addr, hashH := range accounts {
409419
ac := sp.pool.selfPendingAc(addr)

0 commit comments

Comments
 (0)