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 7 #145

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b8d2e66
fix nonce error for debug trace api (#256)
gzliudan May 5, 2023
4678312
Add pull request template
wjrjerome Aug 5, 2023
7b58b85
update the pull request template (#306)
wjrjerome Aug 7, 2023
066adb5
Make the pull request template a bit shorter (#308)
wjrjerome Aug 12, 2023
228a26f
Merge pull request #312 from XinFinOrg/dev-upgrade
liam-lai Aug 25, 2023
34fbba1
internal/ethapi: EstimateGas and Call handle revert error(#173) (#200)
gzliudan Oct 27, 2022
da656a7
Merge pull request #331 from XinFinOrg/dev-upgrade
liam-lai Oct 12, 2023
b93a2b6
Merge pull request #343 from XinFinOrg/dev-upgrade
AnilChinchawale Nov 2, 2023
316200d
fix test by removing v2 switch code
wanwiset25 Apr 4, 2024
ccd6528
remove v2 switch test
wanwiset25 Apr 4, 2024
704629e
separate tests for easier checking
wanwiset25 Apr 4, 2024
98bb6dd
better tests
wanwiset25 Apr 4, 2024
5c8917d
dont fail fast
wanwiset25 Apr 4, 2024
d95ff6f
fix
wanwiset25 Apr 4, 2024
3575685
name
wanwiset25 Apr 4, 2024
a9dc9f0
fix2
wanwiset25 Apr 4, 2024
faa8e6b
fix test
wanwiset25 Apr 5, 2024
325db90
skip for now
wanwiset25 Apr 18, 2024
6050b57
defer time.Since
gzliudan Nov 1, 2023
c3f457d
upgrade the websocket in xdpos (#349)
wjrjerome Nov 6, 2023
f26e7f7
* skip always test
liam-lai Nov 6, 2023
4bec503
internal/ethapi: EstimateGas support parameter blockTag (#326)
gzliudan Oct 11, 2023
93ef75f
Revisit the solution from PR-260, try keep the API consistent by not …
wjrjerome Nov 24, 2023
cacafcc
Improve log (#368)
liam-lai Nov 26, 2023
d09ffec
add flag rpcwritetimeout for rpc http server (#358)
gzliudan Nov 20, 2023
0420c9e
fix import
wanwiset25 Apr 18, 2024
b55c77f
make masternode dynamic
Oct 26, 2023
7212095
fix all the tests
Nov 13, 2023
f2a924d
remove cmt
Nov 13, 2023
dff16d1
fix test again
Nov 13, 2023
4d0f1c5
fix test 1
wanwiset25 Apr 2, 2024
5a3a4d7
fix certThreshold test
wanwiset25 Apr 18, 2024
99eca30
fix print formatting
wanwiset25 Apr 18, 2024
78c582c
fix tests
wanwiset25 Apr 28, 2024
8c1cbb8
Merge pull request #418 from XinFinOrg/dev-upgrade
liam-lai Feb 5, 2024
e4b112f
Merge pull request #428 from XinFinOrg/dev-upgrade
liam-lai Feb 19, 2024
1330db5
fix
wanwiset25 Apr 30, 2024
f1a7faf
Merge pull request #470 from XinFinOrg/dev-upgrade
wanwiset25 Apr 30, 2024
b451ee1
Merge pull request #470 from XinFinOrg/dev-upgrade
wanwiset25 Apr 30, 2024
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
37 changes: 37 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Proposed changes
Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.

## Types of changes

What types of changes does your code introduce to XDC network?
_Put an `✅` in the boxes that apply_

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation Update (if none of the other choices apply)
- [ ] Regular KTLO or any of the maintaince work. e.g code style
- [ ] CICD Improvement

## Impacted Components
Which part of the codebase this PR will touch base on,

_Put an `✅` in the boxes that apply_

- [ ] Consensus
- [ ] Account
- [ ] Network
- [ ] Geth
- [ ] Smart Contract
- [ ] External components
- [ ] Not sure (Please specify below)

## Checklist
_Put an `✅` in the boxes once you have confirmed below actions (or provide reasons on not doing so) that_

- [ ] This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
- [ ] Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
- [ ] Tested the backwards compatibility.
- [ ] Tested with XDC nodes running this version co-exist with those running the previous version.
- [ ] Relevant documentation has been updated as part of this PR
- [ ] N/A
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ profile.cov

**/yarn-error.log
coverage.txt
go.sum
go.sum
32 changes: 16 additions & 16 deletions XDCx/XDCx.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,14 @@ func NewMongoDBEngine(cfg *Config) *XDCxDAO.MongoDatabase {
}

func New(cfg *Config) *XDCX {
tokenDecimalCache, _ := lru.New(defaultCacheLimit)
orderCache, _ := lru.New(tradingstate.OrderCacheLimit)
tokenDecimalCache, err := lru.New(defaultCacheLimit)
if err != nil {
log.Warn("[XDCx-New] fail to create new lru for token decimal", "error", err)
}
orderCache, err := lru.New(tradingstate.OrderCacheLimit)
if err != nil {
log.Warn("[XDCx-New] fail to create new lru for order", "error", err)
}
XDCX := &XDCX{
orderNonce: make(map[common.Address]*big.Int),
Triegc: prque.New(),
Expand All @@ -121,7 +127,10 @@ func New(cfg *Config) *XDCX {

// Overflow returns an indication if the message queue is full.
func (XDCx *XDCX) Overflow() bool {
val, _ := XDCx.settings.Load(overflowIdx)
val, ok := XDCx.settings.Load(overflowIdx)
if !ok {
log.Warn("[XDCx-Overflow] fail to load overflow index")
}
return val.(bool)
}

Expand Down Expand Up @@ -198,20 +207,12 @@ func (XDCx *XDCX) ProcessOrderPending(header *types.Header, coinbase common.Addr
S: common.BigToHash(S),
},
}
cancel := false
if order.Status == tradingstate.OrderStatusCancelled {
cancel = true
}

log.Info("Process order pending", "orderPending", order, "BaseToken", order.BaseToken.Hex(), "QuoteToken", order.QuoteToken)
originalOrder := &tradingstate.OrderItem{}
*originalOrder = *order
originalOrder.Quantity = tradingstate.CloneBigInt(order.Quantity)

if cancel {
order.Status = tradingstate.OrderStatusCancelled
}

newTrades, newRejectedOrders, err := XDCx.CommitOrder(header, coinbase, chain, statedb, XDCXstatedb, tradingstate.GetTradingOrderBookHash(order.BaseToken, order.QuoteToken), order)

for _, reject := range newRejectedOrders {
Expand Down Expand Up @@ -579,17 +580,16 @@ func (XDCX *XDCX) GetEmptyTradingState() (*tradingstate.TradingStateDB, error) {
func (XDCx *XDCX) GetStateCache() tradingstate.Database {
return XDCx.StateCache
}

func (XDCx *XDCX) HasTradingState(block *types.Block, author common.Address) bool {
root, err := XDCx.GetTradingStateRoot(block, author)
if err != nil {
return false
}
_, err = XDCx.StateCache.OpenTrie(root)
if err != nil {
return false
}
return true
return err == nil
}

func (XDCx *XDCX) GetTriegc() *prque.Prque {
return XDCx.Triegc
}
Expand Down Expand Up @@ -639,7 +639,7 @@ func (XDCx *XDCX) RollbackReorgTxMatch(txhash common.Hash) error {
continue
}
orderCacheAtTxHash := c.(map[common.Hash]tradingstate.OrderHistoryItem)
orderHistoryItem, _ := orderCacheAtTxHash[tradingstate.GetOrderHistoryKey(order.BaseToken, order.QuoteToken, order.Hash)]
orderHistoryItem := orderCacheAtTxHash[tradingstate.GetOrderHistoryKey(order.BaseToken, order.QuoteToken, order.Hash)]
if (orderHistoryItem == tradingstate.OrderHistoryItem{}) {
log.Debug("XDCx reorg: remove order due to empty orderHistory", "order", tradingstate.ToJSON(order))
if err := db.DeleteObject(order.Hash, &tradingstate.OrderItem{}); err != nil {
Expand Down
64 changes: 50 additions & 14 deletions XDCx/order_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package XDCx

import (
"encoding/json"
"github.com/XinFinOrg/XDC-Subnet/core/types"
"math/big"
"strconv"
"time"

"github.com/XinFinOrg/XDC-Subnet/core/types"

"github.com/XinFinOrg/XDC-Subnet/consensus"

"fmt"
Expand Down Expand Up @@ -303,7 +304,10 @@ func (XDCx *XDCX) processOrderList(coinbase common.Address, chain consensus.Chai
}
if tradedQuantity.Sign() > 0 {
quantityToTrade = tradingstate.Sub(quantityToTrade, tradedQuantity)
tradingStateDB.SubAmountOrderItem(orderBook, orderId, price, tradedQuantity, side)
err := tradingStateDB.SubAmountOrderItem(orderBook, orderId, price, tradedQuantity, side)
if err != nil {
log.Warn("processOrderList SubAmountOrderItem", "err", err, "orderBook", orderBook, "orderId", orderId, "price", *price, "tradedQuantity", *tradedQuantity, "side", side)
}
tradingStateDB.SetLastPrice(orderBook, price)
log.Debug("Update quantity for orderId", "orderId", orderId.Hex())
log.Debug("TRADE", "orderBook", orderBook, "Taker price", price, "maker price", order.Price, "Amount", tradedQuantity, "orderId", orderId, "side", side)
Expand Down Expand Up @@ -589,11 +593,22 @@ func DoSettleBalance(coinbase common.Address, takerOrder, makerOrder *tradingsta
masternodeOwner := statedb.GetOwner(coinbase)
statedb.AddBalance(masternodeOwner, matchingFee)

tradingstate.SetTokenBalance(takerOrder.UserAddress, newTakerInTotal, settleBalance.Taker.InToken, statedb)
tradingstate.SetTokenBalance(takerOrder.UserAddress, newTakerOutTotal, settleBalance.Taker.OutToken, statedb)

tradingstate.SetTokenBalance(makerOrder.UserAddress, newMakerInTotal, settleBalance.Maker.InToken, statedb)
tradingstate.SetTokenBalance(makerOrder.UserAddress, newMakerOutTotal, settleBalance.Maker.OutToken, statedb)
err = tradingstate.SetTokenBalance(takerOrder.UserAddress, newTakerInTotal, settleBalance.Taker.InToken, statedb)
if err != nil {
log.Warn("DoSettleBalance SetTokenBalance", "err", err, "takerOder.UserAddress", takerOrder.UserAddress, "newTakerInTotal", *newTakerInTotal, "settleBalance.Taker.InToken", settleBalance.Taker.InToken)
}
err = tradingstate.SetTokenBalance(takerOrder.UserAddress, newTakerOutTotal, settleBalance.Taker.OutToken, statedb)
if err != nil {
log.Warn("DoSettleBalance SetTokenBalance", "err", err, "takerOrder.UserAddress", takerOrder.UserAddress, "newTakerOutTotal", *newTakerOutTotal, "settleBalance.Taker.OutToken", settleBalance.Taker.OutToken)
}
err = tradingstate.SetTokenBalance(makerOrder.UserAddress, newMakerInTotal, settleBalance.Maker.InToken, statedb)
if err != nil {
log.Warn("DoSettleBalance SetTokenBalance", "err", err, "makerOrder.UserAddress", makerOrder.UserAddress, "newMakerInTotal", *newMakerInTotal, "settleBalance.Maker.InToken", settleBalance.Maker.InToken)
}
err = tradingstate.SetTokenBalance(makerOrder.UserAddress, newMakerOutTotal, settleBalance.Maker.OutToken, statedb)
if err != nil {
log.Warn("DoSettleBalance SetTokenBalance", "err", err, "makerOrder.UserAddress", makerOrder.UserAddress, "newMakerOutTotal", *newMakerOutTotal, "settleBalance.Maker.OutToken", settleBalance.Maker.OutToken)
}

// add balance for relayers
//log.Debug("ApplyXDCXMatchedTransaction settle fee for relayers",
Expand All @@ -602,8 +617,14 @@ func DoSettleBalance(coinbase common.Address, takerOrder, makerOrder *tradingsta
// "makerRelayerOwner", makerExOwner,
// "makerFeeToken", quoteToken, "makerFee", settleBalanceResult[makerAddr][XDCx.Fee].(*big.Int))
// takerFee
tradingstate.SetTokenBalance(takerExOwner, newTakerFee, makerOrder.QuoteToken, statedb)
tradingstate.SetTokenBalance(makerExOwner, newMakerFee, makerOrder.QuoteToken, statedb)
err = tradingstate.SetTokenBalance(takerExOwner, newTakerFee, makerOrder.QuoteToken, statedb)
if err != nil {
log.Warn("DoSettleBalance SetTokenBalance", "err", err, "takerExOwner", takerExOwner, "newTakerFee", *newTakerFee, "makerOrder.QuoteToken", makerOrder.QuoteToken)
}
err = tradingstate.SetTokenBalance(makerExOwner, newMakerFee, makerOrder.QuoteToken, statedb)
if err != nil {
log.Warn("DoSettleBalance SetTokenBalance", "err", err, "makerExOwner", makerExOwner, "newMakerFee", *newMakerFee, "makerOrder.QuoteToken", makerOrder.QuoteToken)
}
return nil
}

Expand Down Expand Up @@ -652,7 +673,10 @@ func (XDCx *XDCX) ProcessCancelOrder(header *types.Header, tradingStateDB *tradi
return err, false
}
// relayers pay XDC for masternode
tradingstate.SubRelayerFee(originOrder.ExchangeAddress, common.RelayerCancelFee, statedb)
err = tradingstate.SubRelayerFee(originOrder.ExchangeAddress, common.RelayerCancelFee, statedb)
if err != nil {
log.Warn("ProcessCancelOrder SubRelayerFee", "err", err, "originOrder.ExchangeAddress", originOrder.ExchangeAddress, "common.RelayerCancelFee", *common.RelayerCancelFee)
}
masternodeOwner := statedb.GetOwner(coinbase)
// relayers pay XDC for masternode
statedb.AddBalance(masternodeOwner, common.RelayerCancelFee)
Expand All @@ -661,12 +685,24 @@ func (XDCx *XDCX) ProcessCancelOrder(header *types.Header, tradingStateDB *tradi
switch originOrder.Side {
case tradingstate.Ask:
// users pay token (which they have) for relayer
tradingstate.SubTokenBalance(originOrder.UserAddress, tokenCancelFee, originOrder.BaseToken, statedb)
tradingstate.AddTokenBalance(relayerOwner, tokenCancelFee, originOrder.BaseToken, statedb)
err := tradingstate.SubTokenBalance(originOrder.UserAddress, tokenCancelFee, originOrder.BaseToken, statedb)
if err != nil {
log.Warn("ProcessCancelOrder SubTokenBalance", "err", err, "originOrder.UserAddress", originOrder.UserAddress, "tokenCancelFee", *tokenCancelFee, "originOrder.BaseToken", originOrder.BaseToken)
}
err = tradingstate.AddTokenBalance(relayerOwner, tokenCancelFee, originOrder.BaseToken, statedb)
if err != nil {
log.Warn("ProcessCancelOrder AddTokenBalance", "err", err, "relayerOwner", relayerOwner, "tokenCancelFee", *tokenCancelFee, "originOrder.BaseToken", originOrder.BaseToken)
}
case tradingstate.Bid:
// users pay token (which they have) for relayer
tradingstate.SubTokenBalance(originOrder.UserAddress, tokenCancelFee, originOrder.QuoteToken, statedb)
tradingstate.AddTokenBalance(relayerOwner, tokenCancelFee, originOrder.QuoteToken, statedb)
err := tradingstate.SubTokenBalance(originOrder.UserAddress, tokenCancelFee, originOrder.QuoteToken, statedb)
if err != nil {
log.Warn("ProcessCancelOrder SubTokenBalance", "err", err, "originOrder.UserAddress", originOrder.UserAddress, "tokenCancelFee", *tokenCancelFee, "originOrder.QuoteToken", originOrder.QuoteToken)
}
err = tradingstate.AddTokenBalance(relayerOwner, tokenCancelFee, originOrder.QuoteToken, statedb)
if err != nil {
log.Warn("ProcessCancelOrder AddTokenBalance", "err", err, "relayerOwner", relayerOwner, "tokenCancelFee", *tokenCancelFee, "originOrder.QuoteToken", originOrder.QuoteToken)
}
default:
}
// update cancel fee
Expand Down
Loading
Loading