Commit graph

13951 commits

Author SHA1 Message Date
Daniel Liu
adcc0d3652
miner: fix overflow when compare block number (#1895) 2026-01-05 12:15:04 +05:30
Daniel Liu
1886219894
core/txpool: use right type for field Txs in NewTxsEvent (#1897)
This commit updates the Txs field in NewTxsEvent to use []*types.Transaction instead of types.Transactions. This ensures type consistency for event broadcasting and handling, improving reliability of transaction propagation across the network. The change also removes unnecessary goroutine usage for txFeed.Send, making event delivery synchronous and safer for downstream consumers.
2026-01-05 12:12:28 +05:30
wit liu
3fb8b87a87
eth/filters: terminate pending tx subscription on error #32794 (#1901) 2026-01-04 17:31:29 +05:30
wit liu
acd3eb93e8
core: use max to simplify function CalcGasLimit (#1902) 2026-01-04 17:30:47 +05:30
wit liu
267222d4a5
all: fix goimports warning (#1903) 2026-01-04 17:22:26 +05:30
Daniel Liu
ca9e69c924
miner: log commit and finalize time for new block (#1904) 2026-01-04 17:21:49 +05:30
Daniel Liu
be5cfd9756
core, miner: log gas limit error when pack transactions (#1905) 2026-01-04 17:21:34 +05:30
wit liu
51e3c866c8
ethapi: fix ineffassign warning (#1907) 2026-01-04 17:21:09 +05:30
Daniel Liu
2a56eccf45
core/types: correct chainId check for pragueSigner #31032 #31054 (#1885) 2025-12-25 10:33:47 +05:30
Daniel Liu
292c0506c0
core/txpool, eth: refactor function IsSigner (#1889) 2025-12-25 09:27:37 +05:30
wit liu
1394ea09f0
node: fix error condition in gzipResponseWriter.init() #32896 (#1888) 2025-12-25 09:27:11 +05:30
Daniel Liu
6a3b92b701
core/types: change SetCodeTx.ChainID to uint256 #30982 (#1840) 2025-12-25 09:26:44 +05:30
Daniel Liu
aa8c43caf3
core/txpool: make tx validation reusable across packages/pools #27429 (#1873) 2025-12-23 16:28:30 +05:30
Wanwiset Peerapatanapokin
4f89e3fb24
cmd/puppeth: increase gaslimit during genesis block creation (#1851)
* increase gaslimit during genesis block creation for puppeth command

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-23 16:27:03 +05:30
Wanwiset Peerapatanapokin
9a61a4958d
consensus: verify timeout from epochInfo instead of snap.NextEpochCandidates, close XFN-62 (#1850)
* use epochInfo.Masternodes instead of snap.NextEpochCandidates

* remove missing snapshot test (now irrelevant)

* add masternodes length check in getEpochSwitchInfo

* get blockhash directly from vote object
2025-12-23 16:24:54 +05:30
Anil Chinchawale
0f682a8356
Add GitHub Copilot instructions for XDC Network client (#1869)
Added instructions for code review and best practices.
2025-12-23 16:24:36 +05:30
Daniel Liu
3fd03e0814
core, core/types: rename AuthList to SetCodeAuthorizations #30935 (#1884) 2025-12-23 15:40:53 +05:30
Daniel Liu
835579e304
core/txpool: add validation and comprehensive tests for SetGasPrice (#1876)
This commit adds robust input validation to the SetGasPrice method and
implements comprehensive table-driven tests to ensure correct behavior.

Changes in core/txpool/txpool.go:
- Add nil gas price validation with graceful error handling
- Add validation to reject negative gas prices
- Add validation to reject gas prices exceeding 1000 GWei maximum
- Return detailed error messages for each validation failure
- Log warnings when invalid gas prices are rejected

Changes in eth/api_miner.go:
- Update MinerAPI.SetGasPrice to check error return from txPool.SetGasPrice
- Return false when validation fails (when SetGasPrice returns error)
- Return true when validation succeeds (when SetGasPrice returns nil)

New tests in core/txpool/txpool_test.go:
- Implement TestSetGasPrice using table-driven test pattern
- Test 4 invalid cases: nil, negative, exceed max+1, exceed 10000 GWei
- Test 7 valid cases: 0, 1 wei, 1 GWei, 100 GWei, 500 GWei, max-1, max
- Each test case includes expected error value for precise validation
- All 11 test cases verify both error returns and gas price state
- Tests use isolated pool instances to ensure independence
2025-12-23 15:40:24 +05:30
Daniel Liu
3bb3f80f5b
core/state: add account address to Trie slot accessors #26934 (#1140)
This changes the Trie interface to add the plain account address as a
parameter to all storage-related methods.

After the introduction of the TryAccount* functions, TryGet, TryUpdate and
TryDelete are now only meant to read an account's storage. In their current
form, they assume that an account storage is stored in a separate trie, and
that the hashing of the slot is independent of its account's address.

The proposed structure for a stateless storage breaks these two
assumptions: the hashing of a slot key requires the address and all slots
and accounts are stored in a single trie.

This PR therefore adds an address parameter to the interface. It is ignored
in the MPT version, so this change has no functional impact, however it
will reduce the diff size when merging verkle trees.

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
2025-12-23 15:39:56 +05:30
wit liu
55c2d47c45
all: use 0x-prefix string for type Address in error message (#1835) 2025-12-23 15:39:23 +05:30
wit liu
13b0e39412
core/txpool: remove unused function GetSender (#1886) 2025-12-23 11:56:34 +05:30
Daniel Liu
d78d79add0
core/txpool: allow zero tip transactions with minimum gas price enforcement (#1879)
This commit simplifies the transaction pool's gas price validation logic while
maintaining network security through the existing minimum gas price requirement.

Changes:
- Set default PriceLimit to 0 (was 1), allowing transactions with zero tip
- Remove PriceLimit >= 1 validation in config sanitization
- Simplify Pending() method by using EffectiveGasTipIntCmp consistently
- Unify validateTxBasics() logic to use GasTipCapIntCmp for all transactions

Key Points:
1. Economic Protection: All transactions still require gasPrice >= 12.5 Gwei
   (enforced by GetMinGasPrice check in validateTx), providing sufficient
   protection against DoS attacks even with zero tip.

2. Miner Incentives: Since XDPoSChain includes baseFee in miner rewards
   (unlike standard EIP-1559), miners still earn the full gasPrice even when
   tip is 0. This maintains miner revenue while allowing greater flexibility.

3. Special Transactions: BlockSigner and Randomize contract transactions
   remain exempt from gas price checks, as they are critical for consensus.

4. Code Quality: Reduces complexity by 11 lines and unifies validation logic,
   making the codebase more maintainable.

Security Analysis:
- No nil pointer risks: EffectiveGasTipIntCmp has built-in nil handling
- No DoS vulnerability: 12.5 Gwei minimum ensures economic cost per transaction
- EIP-1559 compatible: Existing minGasPrice check covers all validation needs
- Backward compatible: Only relaxes restrictions, doesn't break existing behavior

This change benefits system transactions and special use cases while maintaining
all existing security guarantees through the network's minimum gas price floor.
2025-12-22 12:51:48 +05:30
Daniel Liu
63783a6b4c
core/state, trie: port changes from PBSS #26763 (#1137)
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2025-12-22 12:03:56 +05:30
Daniel Liu
8c380e76f5
core, eth/tracers: support debug_traceCall for special tx, fix #1870 (#1872)
- Fix "invalid transaction v, r, s values" error when calling debug_traceCall
  on BlockSigners contract (0x89)
- Fix "nonce too low" error by respecting Message.SkipNonceChecks flag
- ApplySignTransaction now accepts *Message and uses msg.From directly
- Add fallback to signature recovery for real transactions
- Skip nonce validation when SkipNonceChecks=true (for traceCall)
- Add comprehensive unit tests for both scenarios

Root cause: BlockSigners uses special fast-path that calls
ApplySignTransaction directly, which previously attempted signature
recovery on unsigned transactions from debug_traceCall.

Fixes #1870
2025-12-22 12:02:05 +05:30
Daniel Liu
1a9935625f
cmd/XDC: fix txpool gasPrice being overridden at checkpoints (#1878)
This commit removes two redundant SetGasPrice() calls in the startNode function that were causing multiple issues:

1. Overriding txpool's configured price limit with the miner's gas price setting, mixing two independent configurations:

- cfg.Eth.GasPrice (from --miner-gasprice --gasprice flag)
- cfg.TxPool.PriceLimit (from --txpool-pricelimit flag)

2. Reverting runtime gasPrice changes made via RPC. When users call miner_setGasPrice RPC method to adjust the gasPrice dynamically, the changes would be unexpectedly reverted at the next checkpoint when startNode re-applies cfg.Eth.GasPrice.

The txpool already initializes its gasPrice from config.PriceLimit during construction (core/txpool/txpool.go:333):

```go
func NewTxPool(config Config, chainconfig *params.ChainConfig, chain blockChain) *TxPool {
	pool := &TxPool{
		gasPrice:         new(big.Int).SetUint64(config.PriceLimit),
	}
```

When mining is started via RPC (miner_start), the MinerAPI.Start() method handles gasPrice propagation correctly.

This change ensures:

- The txpool respects its own configuration
- Runtime gasPrice adjustments via RPC persist across checkpoints
- No unexpected overriding of user-configured values
2025-12-22 12:01:38 +05:30
Daniel Liu
1dd09427ed
core/txpool: fix global MinGasPrice override and single test failure, fix #1881 (#1880)
Since commit 845d3d49e (July 2023), MinGasPrice validation (250000000 wei /
0.25 Gwei) has been enforced for all non-special transactions in validateTx().
Later, commit 141cb75c (Dec 2025) refactored this validation logic into the
standalone ValidateTransactionWithState() function for code reusability.

However, the transaction pool test suite was never updated to comply with the
MinGasPrice requirement and continued using extremely low gas prices (1-6 wei),
causing test failures when run independently.

The root cause of this issue was that testQueueTimeLimiting() set the global
variable 'common.MinGasPrice = big.NewInt(0)' without restoring it. This global
variable modification created severe testing problems:

1. Intermittent, non-deterministic failures: The same test would randomly pass
   or fail without any code changes, depending on whether testQueueTimeLimiting
   had executed and set MinGasPrice=0 before other tests checked it

2. Race conditions in concurrent execution: Since tests use t.Parallel(), multiple
   tests could simultaneously access the shared global MinGasPrice variable,
   creating unpredictable timing-dependent behavior

3. Test order dependency: When running 'make test', if testQueueTimeLimiting
   executed early and set MinGasPrice=0, other tests with low gas prices would
   pass. Running the same tests individually or in a different order would fail
   with 'under min gas price' errors

4. Global state pollution: The MinGasPrice modification affected ALL concurrently
   running tests in the suite, violating test isolation principles and making
   debugging extremely difficult

5. Masked real validation issues: The global override hid the fact that test
   transactions violated MinGasPrice requirements that would be enforced in
   production, reducing test effectiveness

6. No cleanup mechanism: The changed value was never restored, permanently
   affecting subsequent tests and creating cascading failures

This intermittent behavior made CI/CD pipelines unreliable - tests could pass
locally but fail in CI, or pass on retry without changes, wasting developer time
investigating 'phantom' failures.

This commit systematically updates all affected test cases to use gas prices
that satisfy the MinGasPrice requirement:

- Replace transaction() helper calls with pricedTransaction() using gas prices
  >= 250000000 wei (MinGasPrice)
- Update dynamicFeeTx() calls to use gasFeeCap and gasTipCap >= 250000000 wei
- Scale account balances proportionally to cover the higher transaction costs
- Maintain test logic and relative price relationships between transactions

Tests fixed (36 total):
- TestStateChangeDuringReset
- TestInvalidTransactions
- TestChainFork
- TestDoubleNonce
- TestMissingNonce
- TestNonceRecovery
- TestPostponing
- TestGapFilling
- TestQueueAccountLimiting
- TestQueueGlobalLimiting
- TestQueueGlobalLimitingNoLocals
- TestQueueTimeLimiting
- TestQueueTimeLimitingNoLocals
- TestPendingLimiting
- TestPendingGlobalLimiting
- TestAllowedTxSize
- TestCapClearsFromAll
- TestPendingMinimumAllowance
- TestRepricing
- TestRepricingDynamicFee
- TestRepricingKeepsLocals
- TestPoolUnderpricing
- TestPoolStableUnderpricing
- TestUnderpricingDynamicFee
- TestDualHeapEviction
- TestDeduplication
- TestReplacement
- TestReplacementDynamicFee
- TestJournaling
- TestJournalingNoLocals
- TestStatusCheck
- TestDropping
- TestQueue
- TestQueue2
- TestNegativeValue
- TestSlotCount

All tests now pass consistently when run with: go test ./core/txpool -count=1
2025-12-22 12:01:21 +05:30
Daniel Liu
639531aae9
contracts, tests: fix global variable modifications and remove unsafe parallelism (#1882)
Add defer cleanup for global variables and remove t.Parallel() where
global state is modified to prevent race conditions and test pollution.

Changes:

1. tests/vm_test.go:
   - Add defer to restore common.TIPXDCXCancellationFee
   - Remove t.Parallel() since modifying global variable makes concurrent
     execution unsafe, even with defer cleanup
   - Prevents potential race conditions with other tests in the package

2. contracts/tests/Inherited_test.go:
   - Add defer to restore common.TIPXDCXCancellationFee
   - No t.Parallel() present, so safe with defer alone

3. contracts/trc21issuer/trc21issuer_test.go:
   - Add defer to restore common.TRC21IssuerSMC (was missing)
   - Fix existing bug: restore correct variable common.TRC21GasPriceBefore
     instead of common.TIPTRC21Fee
   - Remove unused variables: token, delay

Rationale for removing t.Parallel():
While defer ensures cleanup after test completion, during test execution
the modified global variable is visible to all concurrent tests. Even
though tests/vm_test.go is currently the only test modifying
TIPXDCXCancellationFee, removing t.Parallel() is the safer approach to
ensure complete test isolation and prevent timing-dependent behavior.

This follows the same principles as the txpool MinGasPrice fix: global
variable modifications should not occur during concurrent test execution.
2025-12-22 12:00:39 +05:30
Daniel Liu
e2da8daab4
core/types: updates for EIP-7702 API functions #30933 (#1827) 2025-12-20 11:13:04 +05:30
Daniel Liu
510be504ef
eth/tracers: prestate lookup EIP7702 delegation account #32080 (#1828)
Implement https://github.com/ethereum/go-ethereum/issues/32078
Parse and lookup the delegation account if EIP7702 is enabled.

---------

Signed-off-by: jsvisa <delweng@gmail.com>
Co-authored-by: Delweng <delweng@gmail.com>
2025-12-20 11:12:33 +05:30
wit liu
256c76d025
go.mod: use toolchain go v1.25.5 (#1883) 2025-12-19 14:38:47 +04:00
Daniel Liu
0d381ece9f
core/types, internal/ethapi: fixes for prague RPC encoding #30926 (#1839) 2025-12-19 14:38:23 +04:00
Daniel Liu
142b1155d8
all: implement eip-7702 set code tx #30078 (#1759) 2025-12-19 14:09:45 +04:00
Daniel Liu
b08622248c
trie: add error-checks #26914 (#1138) 2025-12-19 11:47:02 +04:00
Daniel Liu
56ef5f3956
trie: reduce unit test time #26918 (#1139) 2025-12-19 11:46:35 +04:00
wit liu
75f147a362
common: simplify FileExist helper #32969 (#1871) 2025-12-19 11:07:32 +04:00
wit liu
b3d12e4fda
common: remove unused variables (#1875) 2025-12-19 10:39:23 +04:00
wit liu
a83c43f240
all: use 0x-prefix string for type Address in log message (#1874) 2025-12-19 08:55:21 +04:00
wit liu
d3b35cba42
rpc: fix a flaky test of the websocket #33002 (#1877) 2025-12-19 08:19:47 +04:00
Daniel Liu
d976cc65d2
core/txpool: fix isGapped implementation #27404 (#1864) 2025-12-18 13:15:50 +04:00
Daniel Liu
503d51945b
core/txpool: disallow future churn by remote txs #26907 (#1860) 2025-12-16 11:05:39 +04:00
Daniel Liu
c9a730d859
core/txpool: use atomic int added in go1.19 #26913 (#1856) 2025-12-16 10:43:09 +04:00
Daniel Liu
999ded17da
all: change chain head markers from block to header #26777 (#1846) 2025-12-16 07:36:51 +04:00
Daniel Liu
cbb0605e0f
core/txpool: used priceList.Put instead of heap.Push #26863 (#1855) 2025-12-16 07:34:47 +04:00
Daniel Liu
ed6f9e82fc
core/txpool: allow future local tx #26930 (#1857) 2025-12-16 07:34:20 +04:00
Daniel Liu
0894fcdb6e
core/txpool: use types.EmptyRootHash instead of null #27230 (#1862) 2025-12-16 07:33:45 +04:00
Daniel Liu
ebbbdf2bff
core/state: move state log mechanism to a separate layer #30569 #30732 (#1775) 2025-12-16 07:33:19 +04:00
Daniel Liu
d9867ea87d
core/txpool: move some validation to outside of mutex #27006 (#1858) 2025-12-15 12:34:23 +04:00
Daniel Liu
322ec7f997
core/txpool : fix map size avoid resizing #27221 (#1861) 2025-12-15 12:33:56 +04:00
Daniel Liu
7f89733a09
eth/tracers, core: handle non-EVM tx tracing, fix #1863 (#1865)
* Detect non-EVM special transactions and construct a synthetic top level callFrame in OnTxStart.
* GetResult returns the virtual frame for non-EVM txs to preserve debug API compatibility.
* Add bounds checks in OnTxEnd and OnLog to avoid panics when callstack is empty.
* Add unit tests to verify the fix
2025-12-15 12:33:32 +04:00
Daniel Liu
12554081cd
core/txpool: implement additional DoS defenses #26648 (#1853) 2025-12-15 12:32:47 +04:00