Commit graph

346 commits

Author SHA1 Message Date
Daniel Liu
28739d7863 common: remove usage of deprecated function (#21610) 2024-12-28 09:06:30 +08:00
Daniel Liu
82ff8c19a0 all: remove uses of untyped golang-lru 2024-12-21 14:39:26 +08:00
benjamin202410
21b05243b6
Merge from master mining time patch (#767)
* merge from master

* close channel

* close channel

---------

Co-authored-by: liam.lai <liam.lai@us>
2024-12-19 01:17:29 -08:00
Daniel Liu
6beee27886 metrics, cmd/XDC: change init-process of metrics (#30814)
This PR modifies how the metrics library handles `Enabled`: previously,
the package `init` decided whether to serve real metrics or just
dummy-types.

This has several drawbacks:
- During pkg init, we need to determine whether metrics are enabled or
not. So we first hacked in a check if certain geth-specific
commandline-flags were enabled. Then we added a similar check for
geth-env-vars. Then we almost added a very elaborate check for
toml-config-file, plus toml parsing.

- Using "real" types and dummy types interchangeably means that
everything is hidden behind interfaces. This has a performance penalty,
and also it just adds a lot of code.

This PR removes the interface stuff, uses concrete types, and allows for
the setting of Enabled to happen later. It is still assumed that
`metrics.Enable()` is invoked early on.

The somewhat 'heavy' operations, such as ticking meters and exp-decay,
now checks the enable-flag to prevent resource leak.

The change may be large, but it's mostly pretty trivial, and from the
last time I gutted the metrics, I ensured that we have fairly good test
coverage.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2024-12-13 14:00:14 +08:00
Daniel Liu
cc4ea7a685 metrics: refactor metrics (#28035)
This change includes a lot of things, listed below.

The interfaces have been split up into one write-interface and one read-interface, with `Snapshot` being the gateway from write to read. This simplifies the semantics _a lot_.

Example of splitting up an interface into one readonly 'snapshot' part, and one updatable writeonly part:

```golang
type MeterSnapshot interface {
	Count() int64
	Rate1() float64
	Rate5() float64
	Rate15() float64
	RateMean() float64
}

// Meters count events to produce exponentially-weighted moving average rates
// at one-, five-, and fifteen-minutes and a mean rate.
type Meter interface {
	Mark(int64)
	Snapshot() MeterSnapshot
	Stop()
}
```

This PR makes the concurrency model clearer. We have actual meters and snapshot of meters. The `meter` is the thing which can be accessed from the registry, and updates can be made to it.

- For all `meters`, (`Gauge`, `Timer` etc), it is assumed that they are accessed by different threads, making updates. Therefore, all `meters` update-methods (`Inc`, `Add`, `Update`, `Clear` etc) need to be concurrency-safe.
- All `meters` have a `Snapshot()` method. This method is _usually_ called from one thread, a backend-exporter. But it's fully possible to have several exporters simultaneously: therefore this method should also be concurrency-safe.

TLDR: `meter`s are accessible via registry, all their methods must be concurrency-safe.

For all `Snapshot`s, it is assumed that an individual exporter-thread has obtained a `meter` from the registry, and called the `Snapshot` method to obtain a readonly snapshot. This snapshot is _not_ guaranteed to be concurrency-safe. There's no need for a snapshot to be concurrency-safe, since exporters should not share snapshots.

Note, though: that by happenstance a lot of the snapshots _are_ concurrency-safe, being unmutable minimal representations of a value. Only the more complex ones are _not_ threadsafe, those that lazily calculate things like `Variance()`, `Mean()`.

Example of how a background exporter typically works, obtaining the snapshot and sequentially accessing the non-threadsafe methods in it:
```golang
		ms := metric.Snapshot()
                ...
		fields := map[string]interface{}{
			"count":    ms.Count(),
			"max":      ms.Max(),
			"mean":     ms.Mean(),
			"min":      ms.Min(),
			"stddev":   ms.StdDev(),
			"variance": ms.Variance(),
```

TLDR: `snapshots` are not guaranteed to be concurrency-safe (but often are).

I also changed the `Sample` type: previously, it iterated the samples fully every time `Mean()`,`Sum()`, `Min()` or `Max()` was invoked. Since we now have readonly base data, we can just iterate it once, in the constructor, and set all four values at once.

The same thing has been done for runtimehistogram.

Back when ResettingTImer was implemented, as part of https://github.com/ethereum/go-ethereum/pull/15910, Anton implemented a `Percentiles` on the new type. However, the method did not conform to the other existing types which also had a `Percentiles`.

1. The existing ones, on input, took `0.5` to mean `50%`. Anton used `50` to mean `50%`.
2. The existing ones returned `float64` outputs, thus interpolating between values. A value-set of `0, 10`, at `50%` would return `5`, whereas Anton's would return either `0` or `10`.

This PR removes the 'new' version, and uses only the 'legacy' percentiles, also for the ResettingTimer type.

The resetting timer snapshot was also defined so that it would expose the internal values. This has been removed, and getters for `Max, Min, Mean` have been added instead.

A lot of types were exported, but do not need to be. This PR unexports quite a lot of them.

metrics: refactor metrics (28035)
2024-12-13 14:00:13 +08:00
Daniel Liu
ad5e7d6db3 crypto: add SignatureLength constant and use it everywhere (#19996) 2024-12-09 17:48:59 +08:00
Daniel Liu
92fc843683 crypto: switch over to upstream sha3 package (#18390) 2024-12-09 17:48:59 +08:00
benjamin202410
a8560300a4
fix vote test and optimize log (#750)
Co-authored-by: liam.lai <liam.lai@us>
2024-11-29 03:14:25 -08:00
liam.lai
809242223a bug fix use right block to count vote theshold 2024-11-22 00:04:39 -08:00
Daniel Liu
ed242b4763 all: implement EIP-1153 transient storage (#26003) 2024-11-15 19:39:18 +08:00
Daniel Liu
9b20ac785e consensus/misc: move eip1559 into a package (#27828) 2024-11-01 11:36:53 +08:00
Daniel Liu
e18553b855 all: implement eip-1559 (#22837) 2024-11-01 11:36:52 +08:00
Daniel Liu
363d9784bf engines/engine_v2: fix staticcheck warning S1009: should omit nil check 2024-10-31 21:51:53 +08:00
Daniel Liu
edce9ccb27 all: fix staticcheck warning S1024: not use x.Sub(time.Now()) 2024-10-31 10:49:44 +08:00
Daniel Liu
c36642a0e1 all: fix staticcheck warning ST1008: error should be last return value 2024-10-31 09:51:47 +08:00
Daniel Liu
5f66fb5de0 fix tautological condition: nil == nil 2024-10-31 09:01:12 +08:00
Daniel Liu
6ed8d399c2 fix nil dereference in field selection 2024-10-31 09:01:12 +08:00
liam.icheng.lai
59a7eb1f9f resolve conflict from master 2024-10-30 16:47:26 -07:00
benjamin202410
118ccd08d5
cherry pick epoch api from dev-upgrade (#699)
* cherry-pick-epoch-api
2024-10-29 01:36:22 -07:00
Daniel Liu
a5bc0baba9 all: fix staticcheck warning ST1019: import package twice 2024-10-28 17:45:19 +08:00
wgr523
71b9005f34
feat: add api xdpos_getBlockInfoByEpochNum (#674)
* feat: add api xdpos_getBlockInfoByEpochNum

* feat: add cache round2epochBlockInfo

* fix: round2epochBlockInfo contains round now

* feat: binary search in GetBlockByEpochNumber

* fix: change some code back, refine style
2024-10-28 00:14:30 -07:00
Daniel Liu
4709ca3f13 all: fix staticcheck warning SA1006 2024-10-28 15:13:21 +08:00
Daniel Liu
b68b9c64ea
Merge pull request #685 from gzliudan/emptyroot
all: use unified emptyRootHash and emptyCodeHash
2024-10-25 15:28:51 +08:00
Daniel Liu
a79411fa06 all: fix staticcheck warning ST1005: incorrectly formatted error string 2024-10-24 09:48:20 +08:00
Daniel Liu
464a89074b all: use unified emptyRootHash and emptyCodeHash (#26718) 2024-10-21 17:55:16 +08:00
benjamin202410
042c02ba8c
add last block number for epoch api (#681)
Co-authored-by: Liam Lai <liam@home>
2024-10-20 23:43:23 -07:00
Daniel Liu
8c077345d0 all: removed blockhash from statedb (#23126) 2024-10-18 09:24:52 +08:00
Liam Lai
22fc7d0710 fix conflict 2024-10-16 22:42:53 -07:00
Liam Lai
5f1fb22e51 fix conflict 2024-10-15 19:51:57 -07:00
Liam Lai
b43bb5ed1f api epoch 2024-10-15 19:20:13 -07:00
benjamin202410
eb6d53adf6
Fix getCandidateStatus API (#663)
* Fix getCandidateStatus API

* sync vote message and fix test

* update function name

---------

Co-authored-by: Liam Lai <liam@home>
2024-10-09 22:05:14 -07:00
Liam
e6190dd25f
fix timeout skip condition (#659)
Co-authored-by: 賴怡誠 <laiyicheng@makotos-MBP.lan>
2024-09-30 21:32:22 -07:00
Liam
9751e41dd5
Mainnet debug (#655)
* intro new timeout (#651)

* intro new timeout

* correct comment

* disable ProcessForensics

* disable ProcessForensics

* change version

* enable periodicProfilingFlag

* fix: ignore old timeout msg

* fix: ignore old timeout msg including equal to the current round

* udpate version file
2024-09-30 20:05:14 -07:00
Daniel Liu
edace6ac6c all: change format 0x%x to %#x (#25221) 2024-09-27 15:24:31 +08:00
wgr523
3593abe815
feat: GetEpochNumbersBetween API (#606)
* feat: GetEpochNumbersBetween API

* style: refine GetEpochNumbersBetween API
2024-09-02 00:11:12 -07:00
Liam
e3df8e55a6
remove legacy testnet validate masternode logic (#603)
* remove legacy testnet validate masternode logic

* remove legacy testnet validate masternode logic

* remove legacy testnet validate masternode logic
2024-08-12 00:13:36 -07:00
Liam Lai
3a6b18c5cd Merge branch 'master' into merge-from-master 2024-07-23 00:38:59 -07:00
Daniel Liu
520fb284f5 Revert "revert https://github.com/XinFinOrg/XDPoSChain/pull/497 behavior for v1 engine (#531)"
This reverts commit 2bbecdcbbc.
2024-07-18 10:24:20 +08:00
Daniel Liu
aa88078dd1 core/types: convert status type from uint to uint64 (#16784) 2024-06-20 15:52:32 +08:00
JukLee0ira
2d89951e5b all: use errrors.New instead of empty fmt.Errorf 2024-06-14 19:19:21 +08:00
JukLee0ira
0aab4ced98 common: add binary variables for system contract 2024-06-06 19:33:59 +08:00
JukLee0ira
21c62f9ef0 XDCx,XDCxlending,consensus,core: not compare adresss by String 2024-06-06 19:33:39 +08:00
Daniel Liu
01e1728a94 all: add support for EIP-2718, EIP-2930 transactions (#21502) 2024-05-14 23:15:35 +08:00
Wanwiset Peerapatanapokin
2bbecdcbbc
revert https://github.com/XinFinOrg/XDPoSChain/pull/497 behavior for v1 engine (#531) 2024-05-13 19:26:26 +08:00
Daniel Liu
ec50ca36d9 core, eth, trie: use common/prque (#17508) 2024-05-09 18:38:27 +08:00
Wanwiset Peerapatanapokin
3fe54e28d3
remove uncle block handling (#523) 2024-04-23 09:44:49 +04:00
Liam
5d4ea760d5
revert rename change as change db field name and stops block chain reading from db (#517) 2024-04-08 20:40:20 +08:00
wgr523
c16bd66a8d
Merge pull request #498 from XinFinOrg/ppx-01
PPX-01 add verification of vote signer belonging to masternodes
2024-04-01 20:48:16 +08:00
Liam
d76a573cf2
PPX-01 rename NextEpochMasterNodes to NextEpochCandidates (#510) 2024-03-31 07:27:13 +11:00
Wanwiset Peerapatanapokin
77390d30ce
consensus/clique: add some missing checks (#22836) and updated to latest go-eth code (#474) 2024-03-26 13:22:24 +04:00