Skip to content

Commit aa1cadd

Browse files
Merge pull request #643 from vitelabs/release_v2.13.0
Release v2.13.0
2 parents 0fa4329 + af5c2c9 commit aa1cadd

16 files changed

+280
-57
lines changed

common/upgrade/face.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ func IsVersion11Upgrade(sHeight uint64) bool {
176176
return upgrade.isActive(11, sHeight)
177177
}
178178

179-
func IsVersionXUpgrade(sHeight uint64) bool {
179+
func IsVersion12Upgrade(sHeight uint64) bool {
180180
assertUpgradeNotNil()
181181
return upgrade.isActive(12, sHeight)
182182
}
183+
184+
func IsVersionXUpgrade(sHeight uint64) bool {
185+
assertUpgradeNotNil()
186+
return upgrade.isActive(13, sHeight)
187+
}

common/upgrade/height_point.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package upgrade
2+
3+
type HeightPoint interface {
4+
IsVersion12Upgrade() bool
5+
IsDexFeeUpgrade() bool
6+
}
7+
8+
type heightPoint struct {
9+
height uint64
10+
}
11+
12+
func NewHeightPoint(height uint64) HeightPoint {
13+
return &heightPoint{height}
14+
}
15+
16+
func (p heightPoint) IsDexFeeUpgrade() bool {
17+
return IsDexFeeUpgrade(p.height)
18+
}
19+
20+
func (p heightPoint) IsVersion12Upgrade() bool {
21+
return IsVersion12Upgrade(p.height)
22+
}
23+
24+
type mockHeightPoint struct {
25+
box UpgradeBox
26+
height uint64
27+
}
28+
29+
// IsDexFeeUpgrade implements HeightPoint
30+
func (m mockHeightPoint) IsDexFeeUpgrade() bool {
31+
return m.box.isActive(3, m.height)
32+
}
33+
34+
// IsVersion12Upgrade implements HeightPoint
35+
func (m mockHeightPoint) IsVersion12Upgrade() bool {
36+
return m.box.isActive(12, m.height)
37+
}
38+
39+
func NewMockPoint(height uint64, box UpgradeBox) HeightPoint {
40+
return &mockHeightPoint{box, height}
41+
}

common/upgrade/upgrade_init.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func NewLatestUpgradeBox() *upgradeBox {
5151
Height: 1,
5252
Version: 12,
5353
},
54+
{
55+
Height: 1,
56+
Version: 13,
57+
},
5458
})
5559
}
5660

@@ -111,10 +115,15 @@ func NewMainnetUpgradeBox() *upgradeBox {
111115
Height: 101320000,
112116
Version: 11,
113117
},
118+
{
119+
Name: "Version12",
120+
Height: 116480000,
121+
Version: 12,
122+
},
114123
{
115124
Name: "VersionX",
116125
Height: EndlessHeight,
117-
Version: 12,
126+
Version: 13,
118127
},
119128
})
120129
}

common/upgrade/upgrade_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func TestMainnetUpgradeBox(t *testing.T) {
7272
IsVersion11Upgrade,
7373
101320000,
7474
},
75+
{
76+
IsVersion12Upgrade,
77+
116480000,
78+
},
7579
{
7680
IsVersionXUpgrade,
7781
EndlessHeight,
@@ -80,7 +84,7 @@ func TestMainnetUpgradeBox(t *testing.T) {
8084
for _, ele := range cases {
8185
testUpgradePoint(t, ele.fc, ele.sHeight)
8286
}
83-
assert.Equal(t, (int)(GetLatestPoint().Version), 11)
87+
assert.Equal(t, (int)(GetLatestPoint().Version), 12)
8488
}
8589

8690
func TestLatestUpgradeBox(t *testing.T) {
@@ -136,6 +140,10 @@ func TestLatestUpgradeBox(t *testing.T) {
136140
IsVersion11Upgrade,
137141
1,
138142
},
143+
{
144+
IsVersion12Upgrade,
145+
1,
146+
},
139147
{
140148
IsVersionXUpgrade,
141149
1,

rpcapi/api/dex.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ func getMiningInfo(db interfaces.VmDb, periodId uint64) (mineInfo *apidex.NewRpc
294294
} else {
295295
return
296296
}
297-
if amount, available, success = dex.GetVxAmountToMine(db, periodId, available, dex.RateForStakingMine); success {
297+
298+
rateForStakingMine := dex.GetFeeStakingMineRate(db)
299+
if amount, available, success = dex.GetVxAmountToMine(db, periodId, available, rateForStakingMine); success {
298300
mineInfo.StakingMine = amount.String()
299301
} else {
300302
return

rpcapi/api/dex_fund.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ func (f DexFundApi) GetCurrentVxMineInfo() (mineInfo *apidex.RpcVxMineInfo, err
243243
} else {
244244
return
245245
}
246-
if amount, available, success = dex.GetVxAmountToMine(db, periodId, available, dex.RateForStakingMine); success {
246+
247+
rateForStakingMine := dex.GetFeeStakingMineRate(db)
248+
if amount, available, success = dex.GetVxAmountToMine(db, periodId, available, rateForStakingMine); success {
247249
mineInfo.PledgeMine = amount.String()
248250
} else {
249251
return

rpcapi/api/ledger_v2.go

+3-26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package api
22

33
import (
4-
"bytes"
54
"fmt"
65
"math/big"
76

@@ -12,7 +11,6 @@ import (
1211
"github.com/vitelabs/go-vite/v2/ledger/chain"
1312
chain_plugins "github.com/vitelabs/go-vite/v2/ledger/chain/plugins"
1413
"github.com/vitelabs/go-vite/v2/vm"
15-
"github.com/vitelabs/go-vite/v2/vm/contracts/abi"
1614
"github.com/vitelabs/go-vite/v2/vm/contracts/dex"
1715
"github.com/vitelabs/go-vite/v2/vm/quota"
1816
"github.com/vitelabs/go-vite/v2/vm/util"
@@ -139,7 +137,7 @@ func (l *LedgerApi) GetAccountBlocksByAddress(addr types.Address, index int, cou
139137

140138
// GetAccountBlocksByHeightRange [start,end] sorted by height desc
141139
func (l *LedgerApi) GetAccountBlocksByHeightRange(addr types.Address, start uint64, end uint64) ([]*AccountBlock, error) {
142-
if end-start > 1000 {
140+
if end - start > 1000 {
143141
return nil, fmt.Errorf("height range must be less than 1000")
144142
}
145143

@@ -274,27 +272,6 @@ func (l *LedgerApi) SendRawTransaction(block *AccountBlock) error {
274272
return err
275273
}
276274

277-
{ // @todo delete it
278-
if lb.ToAddress == types.AddressDexFund {
279-
abiContract := abi.ABIDexFund
280-
data := result.AccountBlock.Data
281-
282-
method := abiContract.Methods[abi.MethodNameDexFundPlaceOrder]
283-
for _, method := range abiContract.Methods {
284-
method.Id()
285-
}
286-
if bytes.Equal(method.Id(), data[:4]) {
287-
param := new(dex.ParamPlaceOrder)
288-
if err = abiContract.UnpackMethod(param, abi.MethodNameDexFundPlaceOrder, data); err != nil {
289-
return err
290-
}
291-
if param.OrderType != 0 {
292-
return fmt.Errorf("error order params")
293-
}
294-
}
295-
}
296-
}
297-
298275
if result != nil {
299276
return l.vite.Pool().AddDirectAccountBlock(result.AccountBlock.AccountAddress, result)
300277
} else {
@@ -726,12 +703,12 @@ func (l *LedgerApi) GetChunksV2(startHeight interface{}, endHeight interface{})
726703
if err != nil {
727704
return nil, err
728705
}
729-
706+
730707
if startHeightUint64 > endHeightUint64 {
731708
return nil, fmt.Errorf("startHeight must be less than endHeight")
732709
}
733710

734-
if endHeightUint64-startHeightUint64 > 1000 {
711+
if endHeightUint64 - startHeightUint64 > 1000 {
735712
return nil, fmt.Errorf("height range must be less than 1000")
736713
}
737714

version/buildversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.12.1
1+
v2.13.0

version/buildversion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package version
2-
const VITE_COMMIT_VERSION = "25b479e7f29ab2e0171d132f269a0275ddcb0836"
3-
const VITE_BUILD_VERSION = "v2.12.1"
2+
const VITE_COMMIT_VERSION = "c47fc7729d1a8f27cff4281bf2af6927c7e711bf"
3+
const VITE_BUILD_VERSION = "v2.13.0"

vm/contracts/contracts_dex_fund.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ func (md MethodDexFundTriggerPeriodJob) DoReceive(db interfaces.VmDb, block *led
373373
return handleDexReceiveErr(fundLogger, md.MethodName, fmt.Errorf("no vx available on mine for fee"), sendBlock)
374374
}
375375
case dex.MineVxForStakingJob:
376-
if amount, vxPoolLeaved, success = dex.GetVxAmountToMine(db, param.PeriodId, vxPool, dex.RateForStakingMine); success {
376+
rateForStakingMine := dex.GetFeeStakingMineRate(db)
377+
if amount, vxPoolLeaved, success = dex.GetVxAmountToMine(db, param.PeriodId, vxPool, rateForStakingMine); success {
377378
if refund, err = dex.DoMineVxForStaking(db, vm.ConsensusReader(), param.PeriodId, amount); err != nil {
378379
return handleDexReceiveErr(fundLogger, md.MethodName, err, sendBlock)
379380
}

vm/contracts/dex/calculator.go

+9
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ func RoundAmount(amountF *big.Float) *big.Int {
9494
amount, _ := new(big.Float).SetPrec(bigFloatPrec).Add(amountF, big.NewFloat(0.5)).Int(nil)
9595
return amount
9696
}
97+
func RoundQuantity(quantityF *big.Float) *big.Int {
98+
quantity, _ := new(big.Float).SetPrec(bigFloatPrec).Add(quantityF, big.NewFloat(0.5)).Int(nil)
99+
return quantity
100+
}
101+
102+
func FloorQuantity(quantityF *big.Float) *big.Int {
103+
quantity, _ := quantityF.Int(nil)
104+
return quantity
105+
}
97106

98107
func NegativeAmount(amount []byte) *big.Int {
99108
return new(big.Int).Neg(new(big.Int).SetBytes(amount))

vm/contracts/dex/fund_helper.go

+12
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,14 @@ func MaxTotalFeeRate(order Order) int32 {
569569
}
570570
}
571571

572+
func GenerateHeightPoint(db interfaces.VmDb) upgrade.HeightPoint {
573+
if latestSb, err := db.LatestSnapshotBlock(); err != nil {
574+
panic(err)
575+
} else {
576+
return upgrade.NewHeightPoint(latestSb.Height)
577+
}
578+
}
579+
572580
func IsDexFeeFork(db interfaces.VmDb) bool {
573581
if latestSb, err := db.LatestSnapshotBlock(); err != nil {
574582
panic(err)
@@ -641,6 +649,10 @@ func IsVersion11DeprecateClearingExpiredOrder(db interfaces.VmDb) bool {
641649
return util.CheckFork(db, upgrade.IsVersion11Upgrade)
642650
}
643651

652+
func IsVersion12Upgrade(db interfaces.VmDb) bool {
653+
return util.CheckFork(db, upgrade.IsVersion12Upgrade)
654+
}
655+
644656
func ValidOperatorFeeRate(feeRate int32) bool {
645657
return feeRate >= 0 && feeRate <= MaxOperatorFeeRate
646658
}

vm/contracts/dex/fund_mine.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,28 @@ type mineRate struct {
389389

390390
// -----------------
391391

392+
func GetFeeStakingMineRate(db interfaces.VmDb) string {
393+
if IsVersion12Upgrade(db) {
394+
return RateForStakingMineVersion12
395+
} else {
396+
return RateForStakingMine
397+
}
398+
}
399+
392400
func GetFeeMineRateArr(db interfaces.VmDb) mineRate {
393-
if IsVersion10Upgrade(db) {
401+
if IsVersion12Upgrade(db) {
402+
return rateSumForFeeMineArrVersion12
403+
} else if IsVersion10Upgrade(db) {
394404
return rateSumForFeeMineArrVersion10
395405
} else {
396406
return rateSumForFeeMineArr
397407
}
398408
}
399409

400410
func GetMakerAndMaintainerArr(db interfaces.VmDb) mineRate {
401-
if IsVersion10Upgrade(db) {
411+
if IsVersion12Upgrade(db) {
412+
return rateSumForMakerAndMaintainerMineArrVersion12
413+
} else if IsVersion10Upgrade(db) {
402414
return rateSumForMakerAndMaintainerMineArrVersion10
403415
} else {
404416
return rateSumForMakerAndMaintainerMineArr

vm/contracts/dex/fund_storage.go

+36
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ var (
129129

130130
// RateSumForFeeMine = "0.6" // 15% * 4
131131
RateForStakingMine = "0.2" // 20%
132+
RateForStakingMineVersion12 = "0.1" // 10%
132133
// RateSumForMakerAndMaintainerMine = "0.2" // 10% + 10%
133134

134135
rateSumForFeeMineArr = mineRate{
@@ -198,6 +199,41 @@ var (
198199
},
199200
}
200201

202+
rateSumForFeeMineArrVersion12 = mineRate{
203+
totalRate: "0.5",
204+
total: 4, // 4=1+1+1+1
205+
fields: []mineRateField{
206+
{
207+
field: ViteTokenType,
208+
rate: 1,
209+
}, {
210+
field: EthTokenType,
211+
rate: 1,
212+
}, {
213+
field: BtcTokenType,
214+
rate: 1,
215+
}, {
216+
field: UsdTokenType,
217+
rate: 1,
218+
},
219+
},
220+
}
221+
222+
rateSumForMakerAndMaintainerMineArrVersion12 = mineRate{
223+
totalRate: "0.4", // 40% = 0.15 + 0.25
224+
total: 8,
225+
fields: []mineRateField{
226+
{
227+
field: MineForMaker,
228+
rate: 3,
229+
},
230+
{
231+
field: MineForMaintainer,
232+
rate: 5,
233+
},
234+
},
235+
}
236+
201237
vxMineDust = new(big.Int).Mul(commonTokenPow, big.NewInt(100)) // 100 VITE
202238

203239
ViteTokenDecimals int32 = 18

0 commit comments

Comments
 (0)