Skip to content

Commit 32fa8f1

Browse files
authored
Merge pull request #617 from MinterTeam/dev
v2.1.0
2 parents 3bd9f0d + 7966b73 commit 32fa8f1

13 files changed

Lines changed: 1276 additions & 108 deletions

File tree

.github/workflows/main.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- master
7+
- dev
78

89
pull_request:
910
branches:
@@ -14,7 +15,7 @@ jobs:
1415
env:
1516
CONTAINER_NAME: minter_node
1617
CONTAINER_TIMEOUT_SEC: 30
17-
API_RUN_PORT: 8841
18+
API_RUN_PORT: 8843
1819
SECRET_DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
1920
SECRET_DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
2021
SECRET_DOCKER_HUB_REPO: ${{ secrets.DOCKER_HUB_REPO }}
@@ -29,6 +30,8 @@ jobs:
2930
# if secret DOCKER_HUB_REPO is not set DOCKER_HUB_USER will be used instead of REPO
3031
# otherwise secrets are empty and repo "testbuild" will be used
3132
- name: Set envs
33+
env:
34+
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
3235
run: |
3336
echo ::set-env name=VERSION::$(awk -F\" '/Version =/ { print $2; exit }' < version/version.go)
3437
echo ::set-env name=DOCKER_REPO::$(if [[ "$SECRET_DOCKER_HUB_REPO" == "" ]]; then if [[ "$SECRET_DOCKER_HUB_USER" == "" ]]; then echo "testbuild"; else echo "$SECRET_DOCKER_HUB_USER"; fi; else echo "$SECRET_DOCKER_HUB_REPO"; fi)
@@ -37,13 +40,17 @@ jobs:
3740
run: docker build -t $DOCKER_REPO/$DOCKER_IMAGE:$VERSION . -f ./Dockerfile-ci
3841

3942
- name: Start docker container
40-
run: docker run -d --name $CONTAINER_NAME -p $API_RUN_PORT:8841 $DOCKER_REPO/$DOCKER_IMAGE:$VERSION
43+
run: docker run -d --name $CONTAINER_NAME -p $API_RUN_PORT:8843 $DOCKER_REPO/$DOCKER_IMAGE:$VERSION
4144

4245
- name: Check container is still running
46+
env:
47+
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
4348
run: |
4449
echo ::set-env name=RUN_TEST_RESULT::$(sleep $CONTAINER_TIMEOUT_SEC && if [[ $(docker inspect -f "{{.State.Running}}" $CONTAINER_NAME 2> /dev/null) == true ]]; then echo OK; else echo FAIL; fi)
4550
4651
- name: Check api is available by HTTP (response code is 200)
52+
env:
53+
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
4754
run: |
4855
echo ::set-env name=API_TEST_RESULT::$(if [[ $(curl -LIs localhost:$API_RUN_PORT -o /dev/null -w '%{http_code}') == 200 ]]; then echo OK; else echo FAIL; fi)
4956

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [v2.1.0](https://github.com/MinterTeam/minter-go-node/tree/v2.1.0)
4+
5+
[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v2.0.3...v2.1.0)
6+
7+
### Fixed
8+
9+
- Correction of votes
10+
311
## [v2.0.3](https://github.com/MinterTeam/minter-go-node/tree/v2.0.3)
412

513
[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v2.0.2...v2.0.3)

coreV2/appdb/appdb.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,9 @@ type Version struct {
248248
Height uint64
249249
}
250250

251-
func (appDB *AppDB) GetVersion(height uint64) string {
252-
appDB.GetVersions()
253-
251+
func (appDB *AppDB) GetVersionName(height uint64) string {
254252
lastVersionName := ""
255-
for _, version := range appDB.versions {
253+
for _, version := range appDB.GetVersions() {
256254
if version.Height > height {
257255
return lastVersionName
258256
}
@@ -262,6 +260,18 @@ func (appDB *AppDB) GetVersion(height uint64) string {
262260
return lastVersionName
263261
}
264262

263+
func (appDB *AppDB) GetVersionHeight(name string) uint64 {
264+
var lastVersionHeight uint64
265+
for _, version := range appDB.GetVersions() {
266+
if version.Name == name {
267+
return lastVersionHeight
268+
}
269+
lastVersionHeight = version.Height
270+
}
271+
272+
return lastVersionHeight
273+
}
274+
265275
func (appDB *AppDB) GetVersions() []*Version {
266276
if len(appDB.versions) == 0 {
267277
result, err := appDB.db.Get([]byte(versionsPath))

coreV2/minter/blockchain.go

Lines changed: 102 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
tmjson "github.com/tendermint/tendermint/libs/json"
1919
tmNode "github.com/tendermint/tendermint/node"
2020
rpc "github.com/tendermint/tendermint/rpc/client/local"
21+
"log"
2122
"math/big"
2223
"sync"
2324
"sync/atomic"
@@ -64,13 +65,14 @@ type Blockchain struct {
6465
// currentMempool is responsive for prevent sending multiple transactions from one address in one block
6566
currentMempool *sync.Map
6667

67-
lock sync.RWMutex
68-
haltHeight uint64
69-
cfg *config.Config
70-
storages *utils.Storage
71-
stopChan context.Context
72-
stopped bool
73-
grace *upgrades.Grace
68+
lock sync.RWMutex
69+
haltHeight uint64
70+
cfg *config.Config
71+
storages *utils.Storage
72+
stopChan context.Context
73+
stopped bool
74+
grace *upgrades.Grace
75+
knownUpdates map[string]struct{}
7476
}
7577

7678
// NewMinterBlockchain creates Minter Blockchain instance, should be only called once
@@ -107,6 +109,12 @@ func NewMinterBlockchain(storages *utils.Storage, cfg *config.Config, ctx contex
107109
return app
108110
}
109111

112+
func graceForUpdate(height uint64) *upgrades.GracePeriod {
113+
return upgrades.NewGracePeriod(height, height+120)
114+
}
115+
116+
const haltBlockV210 = 3431238
117+
110118
func (blockchain *Blockchain) initState() {
111119
initialHeight := blockchain.appDB.GetStartHeight()
112120
currentHeight := blockchain.appDB.GetLastHeight()
@@ -126,7 +134,15 @@ func (blockchain *Blockchain) initState() {
126134
blockchain.stateCheck = state.NewCheckState(stateDeliver)
127135

128136
grace := upgrades.NewGrace()
129-
grace.AddGracePeriods(upgrades.NewGracePeriod(initialHeight, initialHeight+120))
137+
grace.AddGracePeriods(upgrades.NewGracePeriod(initialHeight, initialHeight+120),
138+
upgrades.NewGracePeriod(haltBlockV210, haltBlockV210+120))
139+
blockchain.knownUpdates = map[string]struct{}{
140+
"": {}, // default version
141+
// add more for update
142+
}
143+
for _, v := range blockchain.UpdateVersions() {
144+
grace.AddGracePeriods(graceForUpdate(v.Height))
145+
}
130146
blockchain.grace = grace
131147
}
132148

@@ -196,7 +212,15 @@ func (blockchain *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTy
196212

197213
blockchain.calculatePowers(blockchain.stateDeliver.Validators.GetValidators())
198214

199-
if blockchain.isApplicationHalted(height) {
215+
if blockchain.isApplicationHalted(height) && !blockchain.grace.IsUpgradeBlock(height) {
216+
log.Printf("Application halted at height %d\n", height)
217+
blockchain.stop()
218+
return abciTypes.ResponseBeginBlock{}
219+
}
220+
221+
versionName := blockchain.appDB.GetVersionName(height)
222+
if _, ok := blockchain.knownUpdates[versionName]; !ok {
223+
log.Printf("Update your node binary to the latest version: %s", versionName)
200224
blockchain.stop()
201225
return abciTypes.ResponseBeginBlock{}
202226
}
@@ -290,64 +314,75 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.
290314
blockchain.stateDeliver.Validators.PayRewards()
291315
}
292316

293-
if prices := blockchain.isUpdateCommissionsBlock(height); len(prices) != 0 {
294-
blockchain.stateDeliver.Commission.SetNewCommissions(prices)
295-
price := blockchain.stateDeliver.Commission.GetCommissions()
296-
blockchain.eventsDB.AddEvent(&eventsdb.UpdateCommissionsEvent{
297-
Coin: uint64(price.Coin),
298-
PayloadByte: price.PayloadByte.String(),
299-
Send: price.Send.String(),
300-
BuyBancor: price.BuyBancor.String(),
301-
SellBancor: price.SellBancor.String(),
302-
SellAllBancor: price.SellAllBancor.String(),
303-
BuyPoolBase: price.BuyPoolBase.String(),
304-
BuyPoolDelta: price.BuyPoolDelta.String(),
305-
SellPoolBase: price.SellPoolBase.String(),
306-
SellPoolDelta: price.SellPoolDelta.String(),
307-
SellAllPoolBase: price.SellAllPoolBase.String(),
308-
SellAllPoolDelta: price.SellAllPoolDelta.String(),
309-
CreateTicker3: price.CreateTicker3.String(),
310-
CreateTicker4: price.CreateTicker4.String(),
311-
CreateTicker5: price.CreateTicker5.String(),
312-
CreateTicker6: price.CreateTicker6.String(),
313-
CreateTicker7_10: price.CreateTicker7to10.String(),
314-
CreateCoin: price.CreateCoin.String(),
315-
CreateToken: price.CreateToken.String(),
316-
RecreateCoin: price.RecreateCoin.String(),
317-
RecreateToken: price.RecreateToken.String(),
318-
DeclareCandidacy: price.DeclareCandidacy.String(),
319-
Delegate: price.Delegate.String(),
320-
Unbond: price.Unbond.String(),
321-
RedeemCheck: price.RedeemCheck.String(),
322-
SetCandidateOn: price.SetCandidateOn.String(),
323-
SetCandidateOff: price.SetCandidateOff.String(),
324-
CreateMultisig: price.CreateMultisig.String(),
325-
MultisendBase: price.MultisendBase.String(),
326-
MultisendDelta: price.MultisendDelta.String(),
327-
EditCandidate: price.EditCandidate.String(),
328-
SetHaltBlock: price.SetHaltBlock.String(),
329-
EditTickerOwner: price.EditTickerOwner.String(),
330-
EditMultisig: price.EditMultisig.String(),
331-
EditCandidatePublicKey: price.EditCandidatePublicKey.String(),
332-
CreateSwapPool: price.CreateSwapPool.String(),
333-
AddLiquidity: price.AddLiquidity.String(),
334-
RemoveLiquidity: price.RemoveLiquidity.String(),
335-
EditCandidateCommission: price.EditCandidateCommission.String(),
336-
MintToken: price.MintToken.String(),
337-
BurnToken: price.BurnToken.String(),
338-
VoteCommission: price.VoteCommission.String(),
339-
VoteUpdate: price.VoteUpdate.String(),
340-
})
341-
}
342-
blockchain.stateDeliver.Commission.Delete(height)
343-
344-
if v, ok := blockchain.isUpdateNetworkBlock(height); ok {
345-
blockchain.appDB.AddVersion(v, height)
346-
blockchain.eventsDB.AddEvent(&eventsdb.UpdateNetworkEvent{
347-
Version: v,
348-
})
349-
}
350-
blockchain.stateDeliver.Updates.Delete(height)
317+
{
318+
var updateCommissionsBlockPrices []byte
319+
if height < haltBlockV210 {
320+
updateCommissionsBlockPrices = blockchain.isUpdateCommissionsBlock(height)
321+
} else {
322+
updateCommissionsBlockPrices = blockchain.isUpdateCommissionsBlockV2(height)
323+
}
324+
if prices := updateCommissionsBlockPrices; len(prices) != 0 {
325+
blockchain.stateDeliver.Commission.SetNewCommissions(prices)
326+
price := blockchain.stateDeliver.Commission.GetCommissions()
327+
blockchain.eventsDB.AddEvent(&eventsdb.UpdateCommissionsEvent{
328+
Coin: uint64(price.Coin),
329+
PayloadByte: price.PayloadByte.String(),
330+
Send: price.Send.String(),
331+
BuyBancor: price.BuyBancor.String(),
332+
SellBancor: price.SellBancor.String(),
333+
SellAllBancor: price.SellAllBancor.String(),
334+
BuyPoolBase: price.BuyPoolBase.String(),
335+
BuyPoolDelta: price.BuyPoolDelta.String(),
336+
SellPoolBase: price.SellPoolBase.String(),
337+
SellPoolDelta: price.SellPoolDelta.String(),
338+
SellAllPoolBase: price.SellAllPoolBase.String(),
339+
SellAllPoolDelta: price.SellAllPoolDelta.String(),
340+
CreateTicker3: price.CreateTicker3.String(),
341+
CreateTicker4: price.CreateTicker4.String(),
342+
CreateTicker5: price.CreateTicker5.String(),
343+
CreateTicker6: price.CreateTicker6.String(),
344+
CreateTicker7_10: price.CreateTicker7to10.String(),
345+
CreateCoin: price.CreateCoin.String(),
346+
CreateToken: price.CreateToken.String(),
347+
RecreateCoin: price.RecreateCoin.String(),
348+
RecreateToken: price.RecreateToken.String(),
349+
DeclareCandidacy: price.DeclareCandidacy.String(),
350+
Delegate: price.Delegate.String(),
351+
Unbond: price.Unbond.String(),
352+
RedeemCheck: price.RedeemCheck.String(),
353+
SetCandidateOn: price.SetCandidateOn.String(),
354+
SetCandidateOff: price.SetCandidateOff.String(),
355+
CreateMultisig: price.CreateMultisig.String(),
356+
MultisendBase: price.MultisendBase.String(),
357+
MultisendDelta: price.MultisendDelta.String(),
358+
EditCandidate: price.EditCandidate.String(),
359+
SetHaltBlock: price.SetHaltBlock.String(),
360+
EditTickerOwner: price.EditTickerOwner.String(),
361+
EditMultisig: price.EditMultisig.String(),
362+
EditCandidatePublicKey: price.EditCandidatePublicKey.String(),
363+
CreateSwapPool: price.CreateSwapPool.String(),
364+
AddLiquidity: price.AddLiquidity.String(),
365+
RemoveLiquidity: price.RemoveLiquidity.String(),
366+
EditCandidateCommission: price.EditCandidateCommission.String(),
367+
MintToken: price.MintToken.String(),
368+
BurnToken: price.BurnToken.String(),
369+
VoteCommission: price.VoteCommission.String(),
370+
VoteUpdate: price.VoteUpdate.String(),
371+
})
372+
}
373+
blockchain.stateDeliver.Commission.Delete(height)
374+
}
375+
376+
{
377+
if v, ok := blockchain.isUpdateNetworkBlockV2(height); ok {
378+
blockchain.appDB.AddVersion(v, height)
379+
blockchain.eventsDB.AddEvent(&eventsdb.UpdateNetworkEvent{
380+
Version: v,
381+
})
382+
blockchain.grace.AddGracePeriods(graceForUpdate(height))
383+
}
384+
blockchain.stateDeliver.Updates.Delete(height)
385+
}
351386

352387
hasChangedPublicKeys := false
353388
if blockchain.stateDeliver.Candidates.IsChangedPublicKeys() {

coreV2/minter/minter.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ func (blockchain *Blockchain) isApplicationHalted(height uint64) bool {
294294
return false
295295
}
296296

297+
// Deprecated
297298
func (blockchain *Blockchain) isUpdateCommissionsBlock(height uint64) []byte {
298299
commissions := blockchain.stateDeliver.Commission.GetVotes(height)
299300
if len(commissions) == 0 {
@@ -326,16 +327,49 @@ func (blockchain *Blockchain) isUpdateCommissionsBlock(height uint64) []byte {
326327
return nil
327328
}
328329

329-
func (blockchain *Blockchain) isUpdateNetworkBlock(height uint64) (string, bool) {
330+
func (blockchain *Blockchain) isUpdateCommissionsBlockV2(height uint64) []byte {
331+
commissions := blockchain.stateDeliver.Commission.GetVotes(height)
332+
if len(commissions) == 0 {
333+
return nil
334+
}
335+
// calculate total power of validators
336+
maxVotingResult := big.NewFloat(0)
337+
338+
var price string
339+
for _, commission := range commissions {
340+
totalVotedPower := big.NewInt(0)
341+
for _, vote := range commission.Votes {
342+
if power, ok := blockchain.validatorsPowers[vote]; ok {
343+
totalVotedPower.Add(totalVotedPower, power)
344+
}
345+
}
346+
votingResult := new(big.Float).Quo(
347+
new(big.Float).SetInt(totalVotedPower),
348+
new(big.Float).SetInt(blockchain.totalPower),
349+
)
350+
351+
if maxVotingResult.Cmp(votingResult) == -1 {
352+
maxVotingResult = votingResult
353+
price = commission.Price
354+
}
355+
}
356+
if maxVotingResult.Cmp(big.NewFloat(votingPowerConsensus)) == 1 {
357+
return []byte(price)
358+
}
359+
360+
return nil
361+
}
362+
363+
func (blockchain *Blockchain) isUpdateNetworkBlockV2(height uint64) (string, bool) {
330364
versions := blockchain.stateDeliver.Updates.GetVotes(height)
331365
if len(versions) == 0 {
332366
return "", false
333367
}
334368
// calculate total power of validators
335-
maxVotingResult, totalVotedPower := big.NewFloat(0), big.NewInt(0)
336-
369+
maxVotingResult := big.NewFloat(0)
337370
var version string
338371
for _, v := range versions {
372+
totalVotedPower := big.NewInt(0)
339373
for _, vote := range v.Votes {
340374
if power, ok := blockchain.validatorsPowers[vote]; ok {
341375
totalVotedPower.Add(totalVotedPower, power)

coreV2/transaction/sell_coin_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,14 @@ func TestSellCoinTxCustomToCustomCustom2Commission(t *testing.T) {
653653
// check received coins
654654
buyCoinBalance := cState.Accounts.GetBalance(addr, coinToBuyID)
655655
bipReturn := formula.CalculateSaleReturn(initialVolume1, initialReserve1, crr1, toSell)
656-
estimatedReturn := formula.CalculatePurchaseReturn(initialVolume2, initialReserve2, crr2, bipReturn)
657656
commissions := cState.Commission.GetCommissions()
658657
commissionInBaseCoin := tx.Commission(tx.Price(commissions))
659658
if !commissions.Coin.IsBaseCoin() {
660659
commissionInBaseCoin = cState.Swap.GetSwapper(types.GetBaseCoinID(), commissions.Coin).CalculateSellForBuy(commissionInBaseCoin)
661660
}
662-
commission := formula.CalculateSaleAmount(big.NewInt(0).Add(initialVolume2, estimatedReturn), big.NewInt(0).Add(initialReserve2, bipReturn), crr2, commissionInBaseCoin)
661+
commission := formula.CalculateSaleAmount(initialVolume2, initialReserve2, crr2, commissionInBaseCoin)
662+
663+
estimatedReturn := formula.CalculatePurchaseReturn(big.NewInt(0).Sub(initialVolume2, commission), big.NewInt(0).Sub(initialReserve2, commissionInBaseCoin), crr2, bipReturn)
663664

664665
estimatedBuyBalance := big.NewInt(0).Set(estimatedReturn)
665666
estimatedBuyBalance.Sub(estimatedBuyBalance, commission)
@@ -704,7 +705,7 @@ func TestSellCoinTxCustomToCustomCustom2Commission(t *testing.T) {
704705
}
705706

706707
estimatedSupply := big.NewInt(0).Set(initialVolume2)
707-
estimatedSupply.Add(estimatedSupply, formula.CalculatePurchaseReturn(initialVolume2, initialReserve2, crr2, formula.CalculateSaleReturn(initialVolume1, initialReserve1, crr1, toSell)))
708+
estimatedSupply.Add(estimatedSupply, formula.CalculatePurchaseReturn(big.NewInt(0).Sub(initialVolume2, commission), big.NewInt(0).Sub(initialReserve2, commissionInBaseCoin), crr2, formula.CalculateSaleReturn(initialVolume1, initialReserve1, crr1, toSell)))
708709
estimatedSupply.Sub(estimatedSupply, commission)
709710
if coinData.Volume().Cmp(estimatedSupply) != 0 {
710711
t.Fatalf("Wrong coin supply")

0 commit comments

Comments
 (0)