Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From xdpos 1 > 2 #160

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 44 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch: #allow manual trigger to workflow

jobs:
test_build_and_push_to_docker_registry:
test_golang:
name: Test, build and push image to registry
runs-on: ubuntu-latest
env:
Expand All @@ -17,12 +17,48 @@ jobs:
defaults:
run:
working-directory: ${{ env.GOPATH }}/src/XDC-Subnet
strategy:
fail-fast: false
matrix:
include:
- name: A-B tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[a-b].*")
- name: C-[a-m] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[a-m].*")
- name: C-[n-o] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[n-o].*")
- name: C-[p-z] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[p-z].*")
- name: D-I tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[d-i].*")
- name: J-N tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[j-n].*")
- name: O-R tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[o-r].*")
- name: S tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/s.*")
- name: T-Z tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[t-z].*")
steps:
- name: Check out code
uses: actions/checkout@v3
with:
path: ${{ env.GOPATH }}/src/XDC-Subnet

- name: Set up Go 1.21.x
uses: actions/setup-go@v4
with:
go-version: "1.21.x" # The Go version to download (if necessary) and use.
- name: Run tests
run: ${{ matrix.script }}
env:
GO111MODULE: auto

test_nodejs:
name: Run nodejs tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v1
with:
Expand All @@ -32,16 +68,12 @@ jobs:
cd contracts/validator/src
yarn
npx hardhat test
- name: Set up Go 1.21.x
uses: actions/setup-go@v4
with:
go-version: "1.21.x" # The Go version to download (if necessary) and use.
- name: Run tests
run: |
make test
env:
GO111MODULE: auto

build:
needs: [test_golang, test_nodejs]
name: Build and push image to registry
runs-on: ubuntu-latest
steps:
- name: Docker login
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
Expand All @@ -61,5 +93,4 @@ jobs:
- name: Build and push image
run: |
docker build . --file docker/Dockerfile --tag ${{ steps.image.outputs.name }}
docker push ${{ steps.image.outputs.name }}

docker push ${{ steps.image.outputs.name }}
50 changes: 39 additions & 11 deletions .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,57 @@ on:
- master

jobs:
test_on_pr:
name: Run tests on PR
test_golang:
name: Run golang tests
runs-on: ubuntu-latest
env:
GOPATH: ${{ github.workspace }}
GOBIN: ${{ github.workspace }}/bin
defaults:
run:
working-directory: ${{ env.GOPATH }}/src/XDC-Subnet
strategy:
fail-fast: false
matrix:
include:
- name: A-B tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[a-b].*")
- name: C-[a-m] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[a-m].*")
- name: C-[n-o] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[n-o].*")
- name: C-[p-z] tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/c[p-z].*")
- name: D-I tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[d-i].*")
- name: J-N tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[j-n].*")
- name: O-R tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[o-r].*")
- name: S tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/s.*")
- name: T-Z tests
script: go run build/ci.go test -coverage $(go list ./... | grep "github.com/XinFinOrg/XDC-Subnet/[t-z].*")
steps:
- name: Check out code
uses: actions/checkout@v3
with:
path: ${{ env.GOPATH }}/src/XDC-Subnet
- name: Set up Go 1.21.x
uses: actions/setup-go@v4
with:
go-version: "1.21.x" # The Go version to download (if necessary) and use.
- name: Run tests
run: ${{ matrix.script }}
env:
GO111MODULE: auto

test_nodejs:
name: Run nodejs tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v1
with:
Expand All @@ -28,12 +65,3 @@ jobs:
cd contracts/validator/src
yarn
npx hardhat test
- name: Set up Go 1.21.x
uses: actions/setup-go@v4
with:
go-version: "1.21.x" # The Go version to download (if necessary) and use.
- name: Run tests
run: |
make test
env:
GO111MODULE: auto
11 changes: 6 additions & 5 deletions XDCxlending/lendingstate/lendingitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package lendingstate

import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/XinFinOrg/XDC-Subnet/common"
"github.com/XinFinOrg/XDC-Subnet/core/state"
"github.com/XinFinOrg/XDC-Subnet/core/types"
"github.com/XinFinOrg/XDC-Subnet/crypto/sha3"
"github.com/globalsign/mgo/bson"
"math/big"
"strconv"
"time"
)

const (
Expand Down Expand Up @@ -243,7 +244,7 @@ func (l *LendingItem) VerifyLendingSide() error {
}

func (l *LendingItem) VerifyCollateral(state *state.StateDB) error {
if l.CollateralToken.String() == EmptyAddress || l.CollateralToken.String() == l.LendingToken.String() {
if l.CollateralToken.IsZero() || l.CollateralToken == l.LendingToken {
return fmt.Errorf("invalid collateral %s", l.CollateralToken.Hex())
}
validCollateral := false
Expand Down Expand Up @@ -329,7 +330,7 @@ func (l *LendingItem) EncodedSide() *big.Int {
return big.NewInt(1)
}

//verify signatures
// verify signatures
func (l *LendingItem) VerifyLendingSignature() error {
V := big.NewInt(int64(l.Signature.V))
R := l.Signature.R.Big()
Expand Down
13 changes: 6 additions & 7 deletions XDCxlending/order_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,9 @@ func (l *Lending) processOrderList(header *types.Header, coinbase common.Address
collateralToken = oldestOrder.CollateralToken
borrowFee = lendingstate.GetFee(statedb, oldestOrder.Relayer)
}
if collateralToken.String() == lendingstate.EmptyAddress {
if collateralToken.IsZero() {
return nil, nil, nil, fmt.Errorf("empty collateral")
}
collateralPrice := common.BasePrice
depositRate, liquidationRate, recallRate := lendingstate.GetCollateralDetail(statedb, collateralToken)
if depositRate == nil || depositRate.Sign() <= 0 {
return nil, nil, nil, fmt.Errorf("invalid depositRate %v", depositRate)
Expand Down Expand Up @@ -953,11 +952,11 @@ func (l *Lending) GetMediumTradePriceBeforeEpoch(chain consensus.ChainContext, s
return nil, nil
}

//LendToken and CollateralToken must meet at least one of following conditions
//- Have direct pair in XDCX: lendToken/CollateralToken or CollateralToken/LendToken
//- Have pairs with XDC:
//- lendToken/XDC and CollateralToken/XDC
//- XDC/lendToken and XDC/CollateralToken
// LendToken and CollateralToken must meet at least one of following conditions
// - Have direct pair in XDCX: lendToken/CollateralToken or CollateralToken/LendToken
// - Have pairs with XDC:
// - lendToken/XDC and CollateralToken/XDC
// - XDC/lendToken and XDC/CollateralToken
func (l *Lending) GetCollateralPrices(header *types.Header, chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, collateralToken common.Address, lendingToken common.Address) (*big.Int, *big.Int, error) {
// lendTokenXDCPrice: price of ticker lendToken/XDC
// collateralXDCPrice: price of ticker collateralToken/XDC
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string,
return err
}
var (
msg = XDPoSChain.CallMsg{From: opts.From, To: &c.address, Data: input, GasPrice: common.MinGasPrice, Gas: uint64(4200000)}
msg = XDPoSChain.CallMsg{From: opts.From, To: &c.address, Data: input, GasPrice: common.MinGasPrice50x, Gas: uint64(4200000)}
ctx = ensureContext(opts.Context)
code []byte
output []byte
Expand Down
1 change: 1 addition & 0 deletions cmd/XDC/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) {
common.MinGasPrice = big.NewInt(gasPrice)
}
}
common.MinGasPrice50x = common.MinGasPrice50x.Mul(common.MinGasPrice, big.NewInt(50))

// read passwords from environment
passwords := []string{}
Expand Down
4 changes: 2 additions & 2 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ var TRC21GasPrice = big.NewInt(250000000)
var RateTopUp = big.NewInt(90) // 90%
var BaseTopUp = big.NewInt(100)
var BaseRecall = big.NewInt(100)
var TIPTRC21Fee = big.NewInt(13523400)
var TIPTRC21FeeTestnet = big.NewInt(225000)
var TIPTRC21Fee = big.NewInt(0)
var TIPTRC21FeeTestnet = big.NewInt(0)
var LimitTimeFinality = uint64(30) // limit in 30 block

var IgnoreSignerCheckBlockArray = map[uint64]bool{
Expand Down
30 changes: 30 additions & 0 deletions common/gas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package common

import (
"math/big"
)

var MinGasPrice50x = big.NewInt(12500000000)
var GasPrice50x = big.NewInt(12500000000)

func GetGasFee(blockNumber, gas uint64) *big.Int {
fee := new(big.Int).SetUint64(gas)
if blockNumber >= uint64(10) { //temp fix trc21issuer test fail
fee = fee.Mul(fee, GasPrice50x)
}
return fee
}

func GetGasPrice(number *big.Int) *big.Int {
if number == nil {
return new(big.Int).Set(TRC21GasPrice)
}
return new(big.Int).Set(GasPrice50x)
}

func GetMinGasPrice(number *big.Int) *big.Int {
if number == nil {
return new(big.Int).Set(MinGasPrice)
}
return new(big.Int).Set(MinGasPrice50x)
}
6 changes: 6 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) }
func Uint64ToHash(b uint64) Hash { return BytesToHash(new(big.Int).SetUint64(b).Bytes()) }
func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) }

// IsZero returns if a Hash is empty
func (h Hash) IsZero() bool { return h == Hash{} }

// Get the string representation of the underlying hash
func (h Hash) Str() string { return string(h[:]) }
func (h Hash) Bytes() []byte { return h[:] }
Expand Down Expand Up @@ -190,6 +193,9 @@ func IsHexAddress(s string) bool {
return len(s) == 2*AddressLength && isHex(s)
}

// IsZero returns if a address is empty
func (a Address) IsZero() bool { return a == Address{} }

// Get the string representation of the underlying address
func (a Address) Str() string { return string(a[:]) }
func (a Address) Bytes() []byte { return a[:] }
Expand Down
7 changes: 6 additions & 1 deletion consensus/XDPoS/XDPoS.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package XDPoS

import (
"fmt"
"math/big"

"github.com/XinFinOrg/XDC-Subnet/common"
Expand Down Expand Up @@ -88,7 +89,11 @@ func New(chainConfig *params.ChainConfig, db ethdb.Database) *XDPoS {
}
}

log.Info("xdc config loading", "config", config)
if config.V2.SwitchBlock.Uint64()%config.Epoch != 0 {
panic(fmt.Sprintf("v2 switch number is not epoch switch block %d, epoch %d", config.V2.SwitchBlock.Uint64(), config.Epoch))
}

log.Info("xdc config loading", "v2 config", config.V2)

minePeriodCh := make(chan int)

Expand Down
7 changes: 4 additions & 3 deletions consensus/XDPoS/engines/engine_v2/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (x *XDPoS_v2) Initial(chain consensus.ChainReader, header *types.Header) er
}

func (x *XDPoS_v2) initial(chain consensus.ChainReader, header *types.Header) error {
log.Info("[initial] initial v2 related parameters")
log.Warn("[initial] initial v2 related parameters")

if x.highestQuorumCert.ProposedBlockInfo.Hash != (common.Hash{}) { // already initialized
log.Info("[initial] Already initialized", "x.highestQuorumCert.ProposedBlockInfo.Hash", x.highestQuorumCert.ProposedBlockInfo.Hash)
Expand Down Expand Up @@ -234,6 +234,7 @@ func (x *XDPoS_v2) initial(chain consensus.ChainReader, header *types.Header) er
log.Error("[initial] Error while get masternodes", "error", err)
return err
}

snap := newSnapshot(lastGapNum, lastGapHeader.Hash(), masternodes, []common.Address{})
x.snapshots.Add(snap.Hash, snap)
err = storeSnapshot(snap, x.db)
Expand All @@ -244,7 +245,7 @@ func (x *XDPoS_v2) initial(chain consensus.ChainReader, header *types.Header) er
}

// Initial timeout
log.Info("[initial] miner wait period", "period", x.config.V2.CurrentConfig.MinePeriod)
log.Warn("[initial] miner wait period", "period", x.config.V2.CurrentConfig.MinePeriod)
// avoid deadlock
go func() {
x.minePeriodCh <- x.config.V2.CurrentConfig.MinePeriod
Expand All @@ -254,7 +255,7 @@ func (x *XDPoS_v2) initial(chain consensus.ChainReader, header *types.Header) er
x.timeoutWorker.Reset(chain)
x.isInitilised = true

log.Info("[initial] finish initialisation")
log.Warn("[initial] finish initialisation")

return nil
}
Expand Down
Loading