Skip to content

Commit cf651dc

Browse files
Merge branch 'dev-upgrade' into setup-eup7702-for-devnet-testing
2 parents 1dda88f + cc21093 commit cf651dc

File tree

164 files changed

+3016
-1494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+3016
-1494
lines changed

.github/pull_request_template.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
# Proposed changes
2-
Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
2+
3+
<!-- Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. -->
34

45
## Types of changes
56

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

9-
- [ ] Bugfix (non-breaking change which fixes an issue)
10-
- [ ] New feature (non-breaking change which adds functionality)
11-
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
12-
- [ ] Documentation Update (if none of the other choices apply)
13-
- [ ] Regular KTLO or any of the maintaince work. e.g code style
14-
- [ ] CICD Improvement
10+
- [ ] build: Changes that affect the build system or external dependencies
11+
- [ ] ci: Changes to CI configuration files and scripts
12+
- [ ] chore: Changes that don't change source code or tests
13+
- [ ] docs: Documentation only changes
14+
- [ ] feat: A new feature
15+
- [ ] fix: A bug fix
16+
- [ ] perf: A code change that improves performance
17+
- [ ] refactor: A code change that neither fixes a bug nor adds a feature
18+
- [ ] revert: Revert something
19+
- [ ] style: Changes that do not affect the meaning of the code
20+
- [ ] test: Adding missing tests or correcting existing tests
1521

1622
## Impacted Components
17-
Which part of the codebase this PR will touch base on,
1823

24+
Which parts of the codebase do this PR touch?
1925
_Put an `` in the boxes that apply_
2026

2127
- [ ] Consensus
@@ -27,10 +33,11 @@ _Put an `✅` in the boxes that apply_
2733
- [ ] Not sure (Please specify below)
2834

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

3239
- [ ] This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
33-
- [ ] Tested in private network from genesis block.
40+
- [ ] Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
3441
- [ ] Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
3542
- [ ] Tested the backwards compatibility.
3643
- [ ] Tested with XDC nodes running this version co-exist with those running the previous version.

.github/workflows/ci.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ on:
55
types: [opened, synchronize, reopened]
66
push:
77
branches:
8-
- '*'
8+
- "*"
99
tags:
10-
- '*'
10+
- "*"
1111

1212
env:
13-
GOPROXY: https://proxy.golang.org
13+
GOPROXY: https://proxy.golang.org,direct
1414
GO111MODULE: on
1515
tf_version: "1.3.0"
1616
tf_init_cli_options: "-input=false"
@@ -51,11 +51,33 @@ jobs:
5151
uses: actions/checkout@v4
5252
with:
5353
path: ${{ env.GOPATH }}/src/XDPoSChain
54+
# Cache build tools to avoid downloading them each time
55+
- uses: actions/cache@v4
56+
with:
57+
path: ${{ env.GOPATH }}/src/XDPoSChain/build/cache
58+
key: ${{ runner.os }}-build-tools-cache-${{ hashFiles('**/build/checksums.txt') }}
5459
- name: Set up Go
5560
uses: actions/setup-go@v5
5661
with:
5762
cache: false
58-
go-version: '1.25.x'
63+
go-version: "1.25.x"
64+
- name: Check gofmt
65+
run: |
66+
unformatted=$(git ls-files '*.go' | xargs -r gofmt -l)
67+
if [ -n "$unformatted" ]; then
68+
echo "Unformatted files:"
69+
echo "$unformatted"
70+
exit 1
71+
fi
72+
echo "All Go files are properly formatted."
73+
- name: Check go mod tidy
74+
run: |
75+
set -euo pipefail
76+
go mod tidy -diff 2>&1 | sed '/^go: downloading/d'
77+
echo "go.mod and go.sum are tidy."
78+
- name: Validate generated files
79+
run: |
80+
go run build/ci.go generate
5981
- name: Run tests
6082
run: ${{ matrix.script }}
6183
env:
@@ -109,7 +131,7 @@ jobs:
109131
- name: Set up kubectl
110132
uses: azure/setup-kubectl@v4
111133
with:
112-
version: 'v1.19.11'
134+
version: "v1.19.11"
113135
- name: Apply new image version to Kubernetes deployments
114136
run: |
115137
mkdir -p $HOME/.kube

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
fail_fast: true
22
repos:
3+
- repo: https://github.com/compilerla/conventional-pre-commit
4+
rev: v4.3.0
5+
hooks:
6+
- id: conventional-pre-commit
7+
stages: [commit-msg]
8+
args: []
39
- repo: https://github.com/pre-commit/pre-commit-hooks
410
rev: v6.0.0
511
hooks:
@@ -18,3 +24,10 @@ repos:
1824
- id: go-vet
1925
- id: go-imports
2026
- id: go-mod-tidy
27+
- repo: local
28+
hooks:
29+
- id: make-generate
30+
name: make generate
31+
entry: make generate
32+
language: system
33+
pass_filenames: false

XDCx/tradingstate/XDCx_trie.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ func (t *XDCXTrie) Commit(onleaf trie.LeafCallback) (common.Hash, error) {
165165
// PR #1103 causes TestRevertStates and TestDumpState to fail,
166166
// but we will not fix them since XDCx has been abandoned.
167167
// TODO(daniel): The following code may be incorrect, ref PR #25320:
168-
root, nodes := t.trie.Commit(false)
168+
root, nodes, err := t.trie.Commit(false)
169+
if err != nil {
170+
return common.Hash{}, err
171+
}
169172
if nodes != nil {
170173
if err := t.trie.UpdateDb(root, types.EmptyRootHash, 0, trienode.NewWithNodeSet(nodes)); err != nil {
171174
return common.Hash{}, err
@@ -186,8 +189,37 @@ func (t *XDCXTrie) Copy() *XDCXTrie {
186189
// NodeIterator returns an iterator that returns nodes of the underlying trie. Iteration
187190
// starts at the key after the given start key.
188191
func (t *XDCXTrie) NodeIterator(start []byte) trie.NodeIterator {
189-
return t.trie.NodeIterator(start)
192+
trieIt, err := t.trie.NodeIterator(start)
193+
if err != nil {
194+
log.Error(fmt.Sprintf("Unhandled trie error: %v", err))
195+
return errNodeIterator{err: err}
196+
}
197+
return trieIt
198+
}
199+
200+
// errNodeIterator is a safe, non-nil iterator that reports an error and yields no nodes.
201+
// It prevents nil dereferences when callers don't check for a nil iterator.
202+
type errNodeIterator struct {
203+
err error
204+
}
205+
206+
func (it errNodeIterator) Next(bool) bool { return false }
207+
func (it errNodeIterator) Error() error { return it.err }
208+
func (it errNodeIterator) Hash() common.Hash {
209+
return common.Hash{}
210+
}
211+
func (it errNodeIterator) Parent() common.Hash {
212+
return common.Hash{}
213+
}
214+
func (it errNodeIterator) Path() []byte { return nil }
215+
func (it errNodeIterator) NodeBlob() []byte { return nil }
216+
func (it errNodeIterator) Leaf() bool { return false }
217+
func (it errNodeIterator) LeafKey() []byte { return nil }
218+
func (it errNodeIterator) LeafBlob() []byte { return nil }
219+
func (it errNodeIterator) LeafProof() [][]byte {
220+
return nil
190221
}
222+
func (it errNodeIterator) AddResolver(trie.NodeResolver) {}
191223

192224
// hashKey returns the hash of key as an ephemeral buffer.
193225
// The caller must not hold onto the return value because it will become

XDCxlending/lendingstate/XDCx_trie.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ func (t *XDCXTrie) Commit(onleaf trie.LeafCallback) (common.Hash, error) {
161161
// PR #1103 causes TestRevertStates and TestDumpState to fail,
162162
// but we will not fix them since XDCx has been abandoned.
163163
// TODO(daniel): The following code may be incorrect, ref PR #25320:
164-
root, nodes := t.trie.Commit(false)
164+
root, nodes, err := t.trie.Commit(false)
165+
if err != nil {
166+
return common.Hash{}, err
167+
}
165168
if nodes != nil {
166169
if err := t.trie.UpdateDb(root, types.EmptyRootHash, 0, trienode.NewWithNodeSet(nodes)); err != nil {
167170
return common.Hash{}, err
@@ -182,8 +185,37 @@ func (t *XDCXTrie) Copy() *XDCXTrie {
182185
// NodeIterator returns an iterator that returns nodes of the underlying trie. Iteration
183186
// starts at the key after the given start key.
184187
func (t *XDCXTrie) NodeIterator(start []byte) trie.NodeIterator {
185-
return t.trie.NodeIterator(start)
188+
trieIt, err := t.trie.NodeIterator(start)
189+
if err != nil {
190+
log.Error(fmt.Sprintf("Unhandled trie error: %v", err))
191+
return errNodeIterator{err: err}
192+
}
193+
return trieIt
194+
}
195+
196+
// errNodeIterator is a safe, non-nil iterator that reports an error and yields no nodes.
197+
// It prevents nil dereferences when callers don't check for a nil iterator.
198+
type errNodeIterator struct {
199+
err error
200+
}
201+
202+
func (it errNodeIterator) Next(bool) bool { return false }
203+
func (it errNodeIterator) Error() error { return it.err }
204+
func (it errNodeIterator) Hash() common.Hash {
205+
return common.Hash{}
206+
}
207+
func (it errNodeIterator) Parent() common.Hash {
208+
return common.Hash{}
209+
}
210+
func (it errNodeIterator) Path() []byte { return nil }
211+
func (it errNodeIterator) NodeBlob() []byte { return nil }
212+
func (it errNodeIterator) Leaf() bool { return false }
213+
func (it errNodeIterator) LeafKey() []byte { return nil }
214+
func (it errNodeIterator) LeafBlob() []byte { return nil }
215+
func (it errNodeIterator) LeafProof() [][]byte {
216+
return nil
186217
}
218+
func (it errNodeIterator) AddResolver(trie.NodeResolver) {}
187219

188220
// hashKey returns the hash of key as an ephemeral buffer.
189221
// The caller must not hold onto the return value because it will become

accounts/abi/bind/backends/simulated.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func NewXDCSimulatedBackend(alloc types.GenesisAlloc, gasLimit uint64, chainConf
143143
TrieTimeLimit: 5 * time.Minute,
144144
Preimages: true,
145145
}
146-
blockchain, _ := core.NewBlockChain(database, cacheConfig, genesis.Config, consensus, vm.Config{})
146+
blockchain, _ := core.NewBlockChain(database, cacheConfig, &genesis, consensus, vm.Config{})
147147

148148
backend := &SimulatedBackend{
149149
database: database,
@@ -171,7 +171,7 @@ func NewSimulatedBackend(alloc types.GenesisAlloc, gasLimit uint64) *SimulatedBa
171171
database := rawdb.NewMemoryDatabase()
172172
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc}
173173
genesis.MustCommit(database)
174-
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{})
174+
blockchain, _ := core.NewBlockChain(database, nil, &genesis, ethash.NewFaker(), vm.Config{})
175175

176176
backend := &SimulatedBackend{
177177
database: database,
@@ -830,11 +830,11 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query ethereum.Filter
830830
filter = b.filterSystem.NewBlockFilter(*query.BlockHash, query.Addresses, query.Topics)
831831
} else {
832832
// Initialize unset filter boundaried to run from genesis to chain head
833-
from := int64(0)
833+
from := rpc.EarliestBlockNumber.Int64()
834834
if query.FromBlock != nil {
835835
from = query.FromBlock.Int64()
836836
}
837-
to := int64(-1)
837+
to := rpc.LatestBlockNumber.Int64()
838838
if query.ToBlock != nil {
839839
to = query.ToBlock.Int64()
840840
}

build/ci.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,6 @@ func doGenerate() {
348348
}
349349
}
350350
fmt.Println("No stale files detected.")
351-
352-
// Run go mod tidy check.
353-
for _, mod := range goModules {
354-
tidy := tc.Go("mod", "tidy", "-diff")
355-
tidy.Dir = mod
356-
build.MustRun(tidy)
357-
}
358-
fmt.Println("No untidy module files detected.")
359351
}
360352

361353
// doBadDeps verifies whether certain unintended dependencies between some

cicd/local/start.sh

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fi
7373
sync_mode=full
7474
if test -z "$SYNC_MODE"
7575
then
76-
echo "SYNC_MODE not set, default to full" #full or fast
76+
echo "SYNC_MODE not set, default to $sync_mode" #full or fast
7777
else
7878
echo "SYNC_MODE found, set to $SYNC_MODE"
7979
sync_mode=$SYNC_MODE
@@ -82,21 +82,41 @@ fi
8282
gc_mode=archive
8383
if test -z "$GC_MODE"
8484
then
85-
echo "GC_MODE not set, default to archive" #full or archive
85+
echo "GC_MODE not set, default to $gc_mode" #full or archive
8686
else
8787
echo "GC_MODE found, set to $GC_MODE"
8888
gc_mode=$GC_MODE
8989
fi
9090

91+
ethstats_address=localhost:2000
92+
if test -z "$STATS_ADDRESS"
93+
then
94+
echo "STATS_ADDRESS not set, default to $ethstats_address"
95+
else
96+
echo "STATS_ADDRESS found, set to $STATS_ADDRESS"
97+
ethstats_address=$STATS_ADDRESS
98+
fi
99+
100+
ethstats_secret=xinfin_xdpos_hybrid_local_stats
101+
if test -z "$STATS_SECRET"
102+
then
103+
echo "STATS_SECRET not set, default to $ethstats_secret"
104+
else
105+
echo "STATS_SECRET found, set to $STATS_SECRET"
106+
ethstats_secret=$STATS_SECRET
107+
fi
108+
109+
netstats="${NODE_NAME}-${wallet}:$ethstats_secret@$ethstats_address"
91110

92-
echo "Running a node with wallet: ${wallet} at IP: ${instance_ip}"
111+
echo "Running a node with wallet: ${wallet}"
93112
echo "Starting nodes with $bootnodes ..."
94113

95114
# Note: --gcmode=archive means node will store all historical data. This will lead to high memory usage. But sync mode require archive to sync
96115
# https://github.com/XinFinOrg/XDPoSChain/issues/268
97116

98117
XDC \
99118
--gcmode ${gc_mode} --syncmode ${sync_mode} \
119+
--ethstats ${netstats} \
100120
--nat extip:${instance_ip} \
101121
--bootnodes ${bootnodes} \
102122
--datadir /work/xdcchain \

cicd/mainnet/start.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,41 @@ fi
6161

6262
sync_mode=full
6363
if test -z "$SYNC_MODE"; then
64-
echo "SYNC_MODE not set, default to full" #full or fast
64+
echo "SYNC_MODE not set, default to $sync_mode" #full or fast
6565
else
6666
echo "SYNC_MODE found, set to $SYNC_MODE"
6767
sync_mode=$SYNC_MODE
6868
fi
6969

70-
gc_mode=archive
70+
gc_mode=full
7171
if test -z "$GC_MODE"; then
72-
echo "GC_MODE not set, default to archive" #full or archive
72+
echo "GC_MODE not set, default to $gc_mode" #full or archive
7373
else
7474
echo "GC_MODE found, set to $GC_MODE"
7575
gc_mode=$GC_MODE
7676
fi
7777

78+
ethstats_address=stats.xinfin.network:3000
79+
if test -z "$STATS_ADDRESS"
80+
then
81+
echo "STATS_ADDRESS not set, default to $ethstats_address"
82+
else
83+
echo "STATS_ADDRESS found, set to $STATS_ADDRESS"
84+
ethstats_address=$STATS_ADDRESS
85+
fi
86+
87+
ethstats_secret=xinfin_xdpos_hybrid_network_stats
88+
if test -z "$STATS_SECRET"
89+
then
90+
echo "STATS_SECRET not set, default to $ethstats_secret"
91+
else
92+
echo "STATS_SECRET found, set to $STATS_SECRET"
93+
ethstats_secret=$STATS_SECRET
94+
fi
95+
96+
netstats="${NODE_NAME}-${wallet}:$ethstats_secret@$ethstats_address"
97+
7898
INSTANCE_IP=$(curl https://checkip.amazonaws.com)
79-
netstats="${NODE_NAME}-${wallet}-${INSTANCE_IP}:xinfin_xdpos_hybrid_network_stats@stats.xinfin.network:3000"
8099

81100
echo "Running a node with wallet: ${wallet} at IP: ${INSTANCE_IP}"
82101
echo "Starting nodes with $bootnodes ..."

0 commit comments

Comments
 (0)