Skip to content

Commit

Permalink
Merge pull request #733 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v2.6
  • Loading branch information
danil-lashin authored Nov 29, 2021
2 parents 7cf8f1b + 7a48b32 commit 6b078d8
Show file tree
Hide file tree
Showing 125 changed files with 16,608 additions and 1,334 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/m2-testnet.yml → .github/workflows/taconet.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name: m2-testnet
name: taconet

on:
push:
branches: [ v2.0 ]
branches: [ taconet ]

jobs:
build:
name: Build & Deploy
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: ^1.15
go-version: ^1.16

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go mod download
go mod tidy
- name: Build
env:
Expand All @@ -38,14 +38,14 @@ jobs:
target: "/tmp/node"
rm: true

- name: Rename old build
- name: Remove old build
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.NODE_V2_HOST }}
USERNAME: ${{ secrets.NODE_V2_USERNAME }}
PORT: ${{ secrets.NODE_V2_PORT }}
KEY: ${{ secrets.NODE_V2_SSH }}
script: mv /opt/minter/node/minter /opt/minter/node/minter_${{ github.sha }}
script: rm /opt/minter/node/minter

- name: Copy new build
uses: appleboy/ssh-action@master
Expand All @@ -56,6 +56,15 @@ jobs:
KEY: ${{ secrets.NODE_V2_SSH }}
script: mv /tmp/node/build/minter /opt/minter/node/minter

- name: Copy backup build
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.NODE_V2_HOST }}
USERNAME: ${{ secrets.NODE_V2_USERNAME }}
PORT: ${{ secrets.NODE_V2_PORT }}
KEY: ${{ secrets.NODE_V2_SSH }}
script: cp /opt/minter/node/minter /opt/minter/node/minter_${{ github.sha }}

- name: Restart service
uses: appleboy/ssh-action@master
with:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [v2.6.0](https://github.com/MinterTeam/minter-go-node/tree/v2.6.0)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v2.5.0...v2.6.0)

### Added

- AMM with Order Book
- Allow all holders to burn tokens
- Limitation of the maximum total stake of a candidate to 20% of the sum of all candidates
- Removal of candidates that do not fall into the top 100 by stake size

## [v2.5.0](https://github.com/MinterTeam/minter-go-node/tree/v2.5.0)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v2.4.1...v2.5.0)
Expand Down
120 changes: 119 additions & 1 deletion api/v2/service/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/MinterTeam/minter-go-node/coreV2/events"
"github.com/MinterTeam/minter-go-node/coreV2/state/coins"
"github.com/MinterTeam/minter-go-node/coreV2/types"
pb "github.com/MinterTeam/node-grpc-gateway/api_pb"
Expand All @@ -17,6 +18,8 @@ import (
tmTypes "github.com/tendermint/tendermint/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

// Block returns block data at given height.
Expand All @@ -42,7 +45,7 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
if _, ok := fields[pb.BlockField_transactions]; ok {
blockResults, err = s.client.BlockResults(ctx, &height)
if err != nil {
return nil, status.Error(codes.NotFound, "Block results not found")
return nil, status.Error(codes.NotFound, "Block results not found") // fmt.Sprintf("Block results not found: %v", err))
}
}

Expand Down Expand Up @@ -73,6 +76,121 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
TransactionCount: uint64(len(block.Block.Txs)),
}

if req.Events {
loadEvents := s.blockchain.GetEventsDB().LoadEvents(uint32(req.Height))
for _, event := range loadEvents {
var m proto.Message
switch e := event.(type) {
case *events.JailEvent:
m = &pb.JailEvent{
ValidatorPubKey: e.ValidatorPubKeyString(),
JailedUntil: e.JailedUntil,
}
case *events.OrderExpiredEvent:
m = &pb.OrderExpiredEvent{
Id: e.ID,
Address: e.AddressString(),
Coin: e.Coin,
Amount: e.Amount,
}
case *events.RewardEvent:
m = &pb.RewardEvent{
Role: pb.RewardEvent_Role(pb.RewardEvent_Role_value[e.Role]),
Address: e.AddressString(),
Amount: e.Amount,
ForCoin: e.ForCoin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.SlashEvent:
m = &pb.SlashEvent{
Address: e.AddressString(),
Amount: e.Amount,
Coin: e.Coin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.StakeKickEvent:
m = &pb.StakeKickEvent{
Address: e.AddressString(),
Amount: e.Amount,
Coin: e.Coin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.UnbondEvent:
m = &pb.UnbondEvent{
Address: e.AddressString(),
Amount: e.Amount,
Coin: e.Coin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.RemoveCandidateEvent:
m = &pb.RemoveCandidateEvent{
CandidatePubKey: e.CandidatePubKeyString(),
}
case *events.UpdateNetworkEvent:
m = &pb.UpdateNetworkEvent{
Version: e.Version,
}
case *events.UpdateCommissionsEvent:
m = &pb.UpdateCommissionsEvent{
Coin: e.Coin,
PayloadByte: e.PayloadByte,
Send: e.Send,
BuyBancor: e.BuyBancor,
SellBancor: e.SellBancor,
SellAllBancor: e.SellAllBancor,
BuyPoolBase: e.BuyPoolBase,
BuyPoolDelta: e.BuyPoolDelta,
SellPoolBase: e.SellPoolBase,
SellPoolDelta: e.SellPoolDelta,
SellAllPoolBase: e.SellAllPoolBase,
SellAllPoolDelta: e.SellAllPoolDelta,
CreateTicker3: e.CreateTicker3,
CreateTicker4: e.CreateTicker4,
CreateTicker5: e.CreateTicker5,
CreateTicker6: e.CreateTicker6,
CreateTicker7_10: e.CreateTicker7_10,
CreateCoin: e.CreateCoin,
CreateToken: e.CreateToken,
RecreateCoin: e.RecreateCoin,
RecreateToken: e.RecreateToken,
DeclareCandidacy: e.DeclareCandidacy,
Delegate: e.Delegate,
Unbond: e.Unbond,
RedeemCheck: e.RedeemCheck,
SetCandidateOn: e.SetCandidateOn,
SetCandidateOff: e.SetCandidateOff,
CreateMultisig: e.CreateMultisig,
MultisendBase: e.MultisendBase,
MultisendDelta: e.MultisendDelta,
EditCandidate: e.EditCandidate,
SetHaltBlock: e.SetHaltBlock,
EditTickerOwner: e.EditTickerOwner,
EditMultisig: e.EditMultisig,
EditCandidatePublicKey: e.EditCandidatePublicKey,
CreateSwapPool: e.CreateSwapPool,
AddLiquidity: e.AddLiquidity,
RemoveLiquidity: e.RemoveLiquidity,
EditCandidateCommission: e.EditCandidateCommission,
MintToken: e.MintToken,
BurnToken: e.BurnToken,
VoteCommission: e.VoteCommission,
VoteUpdate: e.VoteUpdate,
FailedTx: e.FailedTx,
AddLimitOrder: e.AddLimitOrder,
RemoveLimitOrder: e.RemoveLimitOrder,
}
default:
return nil, status.Error(codes.Internal, "unknown event type")
}

a, err := anypb.New(m)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
response.Events = append(response.Events, a)
}
}

for field := range fields {
if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return nil, timeoutStatus.Err()
Expand Down
2 changes: 2 additions & 0 deletions api/v2/service/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"context"

pb "github.com/MinterTeam/node-grpc-gateway/api_pb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -17,6 +18,7 @@ func (s *Service) Blocks(ctx context.Context, req *pb.BlocksRequest) (*pb.Blocks
Height: i,
Fields: req.Fields,
FailedTxs: req.FailedTxs,
Events: req.Events,
})
if err != nil {
if status.Code(err) == codes.NotFound {
Expand Down
33 changes: 26 additions & 7 deletions api/v2/service/data_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
Stake: d.Stake.String(),
}
case transaction.TypeDelegate:
d := data.(*transaction.DelegateData)
d := data.(*transaction.DelegateDataV260)
m = &pb.DelegateData{
PubKey: d.PubKey.String(),
Coin: &pb.Coin{
Expand Down Expand Up @@ -199,7 +199,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
PubKey: d.PubKey.String(),
}
case transaction.TypeUnbond:
d := data.(*transaction.UnbondData)
d := data.(*transaction.UnbondDataV260)
m = &pb.UnbondData{
PubKey: d.PubKey.String(),
Coin: &pb.Coin{
Expand All @@ -209,7 +209,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
Value: d.Value.String(),
}
case transaction.TypeAddLiquidity:
d := data.(*transaction.AddLiquidityDataV240)
d := data.(*transaction.AddLiquidityDataV260)
m = &pb.AddLiquidityData{
Coin0: &pb.Coin{
Id: uint64(d.Coin0),
Expand Down Expand Up @@ -238,7 +238,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
MinimumVolume1: d.MinimumVolume1.String(),
}
case transaction.TypeBuySwapPool:
d := data.(*transaction.BuySwapPoolDataV240)
d := data.(*transaction.BuySwapPoolDataV260)
var coinsInfo []*pb.Coin
for _, coin := range d.Coins {
coinsInfo = append(coinsInfo, &pb.Coin{
Expand All @@ -252,7 +252,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
MaximumValueToSell: d.MaximumValueToSell.String(),
}
case transaction.TypeSellSwapPool:
d := data.(*transaction.SellSwapPoolDataV240)
d := data.(*transaction.SellSwapPoolDataV260)
var coinsInfo []*pb.Coin
for _, coin := range d.Coins {
coinsInfo = append(coinsInfo, &pb.Coin{
Expand All @@ -266,7 +266,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
MinimumValueToBuy: d.MinimumValueToBuy.String(),
}
case transaction.TypeSellAllSwapPool:
d := data.(*transaction.SellAllSwapPoolDataV240)
d := data.(*transaction.SellAllSwapPoolDataV260)
var coinsInfo []*pb.Coin
for _, coin := range d.Coins {
coinsInfo = append(coinsInfo, &pb.Coin{
Expand Down Expand Up @@ -299,7 +299,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
Burnable: d.Burnable,
}
case transaction.TypeBurnToken:
d := data.(*transaction.BurnTokenData)
d := data.(*transaction.BurnTokenDataV260)
m = &pb.BurnTokenData{
Coin: &pb.Coin{
Id: uint64(d.Coin),
Expand Down Expand Up @@ -346,6 +346,25 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
Volume0: d.Volume0.String(),
Volume1: d.Volume1.String(),
}
case transaction.TypeAddLimitOrder:
d := data.(*transaction.AddLimitOrderData)
m = &pb.AddLimitOrderData{
CoinToBuy: &pb.Coin{
Id: uint64(d.CoinToBuy),
Symbol: rCoins.GetCoin(d.CoinToBuy).GetFullSymbol(),
},
CoinToSell: &pb.Coin{
Id: uint64(d.CoinToSell),
Symbol: rCoins.GetCoin(d.CoinToSell).GetFullSymbol(),
},
ValueToBuy: d.ValueToBuy.String(),
ValueToSell: d.ValueToSell.String(),
}
case transaction.TypeRemoveLimitOrder:
d := data.(*transaction.RemoveLimitOrderData)
m = &pb.RemoveLimitOrderData{
Id: uint64(d.ID),
}
default:
return nil, errors.New("unknown tx type")
}
Expand Down
18 changes: 9 additions & 9 deletions api/v2/service/estimate_coin_buy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"context"
"fmt"
"github.com/MinterTeam/minter-go-node/coreV2/state/coins"
"math/big"

"github.com/MinterTeam/minter-go-node/coreV2/code"
Expand Down Expand Up @@ -184,21 +185,20 @@ func (s *Service) calcBuyFromPool(ctx context.Context, value *big.Int, cState *s
}
}

sellValue := swapChecker.CalculateSellForBuy(buyValue)
if sellValue == nil {
reserve0, reserve1 := swapChecker.Reserves()
symbolOut := coinBuy.GetFullSymbol()
return nil, s.createError(status.New(codes.FailedPrecondition, fmt.Sprintf("You wanted to buy %s %s, but pool reserve has only %s %s", value, symbolOut, reserve1.String(), symbolOut)), transaction.EncodeError(code.NewInsufficientLiquidity(coinFrom.ID().String(), "", coinBuy.ID().String(), value.String(), reserve0.String(), reserve1.String())))
}

coinSell := coinFrom
if sellCoinID != coinSell.ID() {
coinSell = cState.Coins().GetCoin(sellCoinID)
}

if errResp := transaction.CheckSwap(swapChecker, coinSell, coinBuy, sellValue, buyValue, true); errResp != nil {
errResp, sellValue := transaction.CheckSwap(swapChecker, coinSell, coinBuy, coins.MaxCoinSupply(), buyValue, true)
if errResp != nil {
return nil, s.createError(status.New(codes.FailedPrecondition, errResp.Log), errResp.Info)
}
if sellValue == nil || sellValue.Sign() != 1 {
reserve0, reserve1 := swapChecker.Reserves()
symbolOut := coinBuy.GetFullSymbol()
return nil, s.createError(status.New(codes.FailedPrecondition, fmt.Sprintf("You wanted to buy %s %s, but pool reserve has only %s %s", value, symbolOut, reserve1.String(), symbolOut)), transaction.EncodeError(code.NewInsufficientLiquidity(coinFrom.ID().String(), "", coinBuy.ID().String(), value.String(), reserve0.String(), reserve1.String())))
}

buyValue = sellValue
coinBuy = coinSell
Expand Down Expand Up @@ -283,7 +283,7 @@ func (s *Service) calcBuyPoolWithCommission(ctx context.Context, commissions *co

commissionPoolSwapper := cState.Swap().GetSwapper(requestCoinCommissionID, types.GetBaseCoinID())
if commissionFromPool && requestCoinCommissionID != types.GetBaseCoinID() {
commissionPoolSwapper = commissionPoolSwapper.AddLastSwapStep(commission, commissionInBaseCoin)
commissionPoolSwapper = commissionPoolSwapper.AddLastSwapStepWithOrders(commission, commissionInBaseCoin, false)
}

if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
Expand Down
Loading

0 comments on commit 6b078d8

Please sign in to comment.