Skip to content

Commit da9791a

Browse files
authored
Merge pull request #43 from METADIUM/dev
Gmet m0.10.1 to master
2 parents 0651759 + 2f135ff commit da9791a

17 files changed

Lines changed: 650 additions & 45 deletions

File tree

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ gmet-linux:
120120
docker build -t meta/builder:local \
121121
-f Dockerfile.metadium . && \
122122
docker run -e HOME=/tmp --rm -v $(shell pwd):/data \
123-
-u $(shell id -u):$(shell id -g) \
123+
-u $(shell id -u):$(shell id -g) \
124124
-w /data meta/builder:local \
125-
"make USE_ROCKSDB=$(USE_ROCKSDB)"; \
125+
"git config --global --add safe.directory /data;\
126+
make USE_ROCKSDB=$(USE_ROCKSDB)"; \
126127
fi
127128

128129
ifneq ($(USE_ROCKSDB), YES)
@@ -154,6 +155,11 @@ BEGIN { print "package metadium\n"; } \
154155
sub("^var[^(]*\\(","",$$0); sub("\\);$$","",$$0); \
155156
n = "Gov"; \
156157
print "var " n "Abi = `{ \"contractName\": \"" n "\", \"abi\": " $$0 "}`"; \
158+
} \
159+
/^var TRSListImp_contract/ { \
160+
sub("^var[^(]*\\(","",$$0); sub("\\);$$","",$$0); \
161+
n = "TRSList"; \
162+
print "var " n "Abi = `{ \"contractName\": \"" n "\", \"abi\": " $$0 "}`"; \
157163
}'
158164

159165
metadium/governance_abi.go: metadium/contracts/MetadiumGovernance.js

core/error.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,8 @@ var (
108108
// ErrSenderInsufficientFunds is returned if the value cost of executing a transaction
109109
// is higher than the balance of the sender's account.
110110
ErrSenderInsufficientFunds = errors.New("fee delegation: insufficient sender's funds for value")
111+
112+
// Add TRS
113+
// ErrIncludedTRSList is returned if the address included in the TRSList.
114+
ErrIncludedTRSList = errors.New("included in the TRSList")
111115
)

core/state/snapshot/generate.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,7 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er
615615
// If the iterated account is the contract, create a further loop to
616616
// verify or regenerate the contract storage.
617617
if acc.Root == emptyRoot {
618-
log.Debug("removeStorageAt skip for rocksdb")
619-
// ctx.removeStorageAt(account)
618+
ctx.removeStorageAt(account)
620619
} else {
621620
var storeMarker []byte
622621
if accMarker != nil && bytes.Equal(account[:], accMarker) && len(dl.genMarker) > common.HashLength {

core/tx_pool.go

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/ethereum/go-ethereum/core/types"
3535
"github.com/ethereum/go-ethereum/event"
3636
"github.com/ethereum/go-ethereum/log"
37+
metaminer "github.com/ethereum/go-ethereum/metadium/miner"
3738
"github.com/ethereum/go-ethereum/metrics"
3839
"github.com/ethereum/go-ethereum/params"
3940
)
@@ -95,6 +96,8 @@ var (
9596
var (
9697
evictionInterval = time.Minute // Time interval to check for evictable transactions
9798
statsReportInterval = 8 * time.Second // Time interval to report transaction pool stats
99+
// Add TRS
100+
trsTickerInterval = 3 * time.Hour // Time interval to check for TRS transactions
98101
)
99102

100103
var (
@@ -250,6 +253,9 @@ type TxPool struct {
250253
eip1559 bool // Fork indicator whether we are using EIP-1559 type transactions.
251254
// fee delegation
252255
feedelegation bool // Fork indicator whether we are using fee delegation type transactions.
256+
// Add TRS
257+
trsListMap map[common.Address]bool
258+
trsSubscribe bool
253259

254260
currentState *state.StateDB // Current state in the blockchain head
255261
pendingNonces *txNoncer // Pending state tracking virtual nonces
@@ -356,12 +362,16 @@ func (pool *TxPool) loop() {
356362
report = time.NewTicker(statsReportInterval)
357363
evict = time.NewTicker(evictionInterval)
358364
journal = time.NewTicker(pool.config.Rejournal)
365+
// Add TRS
366+
trsTicker = time.NewTicker(trsTickerInterval)
359367
// Track the previous head headers for transaction reorgs
360368
head = pool.chain.CurrentBlock()
361369
)
362370
defer report.Stop()
363371
defer evict.Stop()
364372
defer journal.Stop()
373+
// Add TRS
374+
defer trsTicker.Stop()
365375

366376
// Notify tests that the init phase is done
367377
close(pool.initDoneCh)
@@ -433,6 +443,25 @@ func (pool *TxPool) loop() {
433443
}
434444
pool.mu.Unlock()
435445
}
446+
// Add TRS
447+
case <-trsTicker.C:
448+
// Removes the transaction included in trsList regardless of TRS subscription.
449+
if !metaminer.IsPoW() {
450+
if len(pool.trsListMap) > 0 {
451+
pool.mu.Lock()
452+
for addr := range pool.pending {
453+
list := pool.pending[addr].Flatten()
454+
for _, tx := range list {
455+
if pool.trsListMap[addr] || (tx.To() != nil && pool.trsListMap[*tx.To()]) {
456+
log.Debug("Discard pending transaction included in trsList", "hash", tx.Hash(), "addr", addr)
457+
pool.removeTx(tx.Hash(), true)
458+
pendingDiscardMeter.Mark(int64(1))
459+
}
460+
}
461+
}
462+
pool.mu.Unlock()
463+
}
464+
}
436465
}
437466
}
438467
}
@@ -701,6 +730,16 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
701730
if pool.currentState.GetNonce(from) > tx.Nonce() {
702731
return ErrNonceTooLow
703732
}
733+
// Add TRS
734+
// Only nodes that subscribe to TRS removes transactions included in trsList.
735+
if !metaminer.IsPoW() {
736+
if len(pool.trsListMap) > 0 && pool.trsSubscribe {
737+
if pool.trsListMap[from] || (tx.To() != nil && pool.trsListMap[*tx.To()]) {
738+
return ErrIncludedTRSList
739+
}
740+
}
741+
}
742+
704743
// Transactor should have enough funds to cover the costs
705744
// cost == V + GP * GL
706745

@@ -1400,6 +1439,13 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
14001439
pool.eip1559 = pool.chainconfig.IsLondon(next)
14011440
// fee delegation
14021441
pool.feedelegation = pool.chainconfig.IsApplepie(next)
1442+
// Add TRS
1443+
if !metaminer.IsPoW() {
1444+
pool.trsListMap, pool.trsSubscribe, _ = metaminer.GetTRSListMap(newHead.Number)
1445+
} else {
1446+
pool.trsListMap = nil
1447+
pool.trsSubscribe = false
1448+
}
14031449
}
14041450

14051451
// promoteExecutables moves transactions that have become processable from the
@@ -1425,13 +1471,25 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
14251471
// Drop all transactions that are too costly (low balance or out of gas)
14261472
drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
14271473

1428-
// fee delegation
1429-
if pool.feedelegation {
1474+
// Add TRS
1475+
// Only nodes that subscribe to TRS removes transactions included in trsList.
1476+
doTrs := !metaminer.IsPoW() && len(pool.trsListMap) > 0 && pool.trsSubscribe
1477+
if pool.feedelegation || doTrs {
14301478
for _, tx := range list.Flatten() {
1431-
if tx.Type() == types.FeeDelegateDynamicFeeTxType && tx.FeePayer() != nil {
1432-
feePayer := *tx.FeePayer()
1433-
if pool.currentState.GetBalance(feePayer).Cmp(tx.FeePayerCost()) < 0 {
1434-
log.Trace("promoteExecutables", "hash", tx.Hash().String())
1479+
if pool.feedelegation {
1480+
if tx.Type() == types.FeeDelegateDynamicFeeTxType && tx.FeePayer() != nil {
1481+
feePayer := *tx.FeePayer()
1482+
if pool.currentState.GetBalance(feePayer).Cmp(tx.FeePayerCost()) < 0 {
1483+
log.Trace("Removed queued fee delegation transaction", "hash", tx.Hash().String())
1484+
list.Remove(tx)
1485+
drops = append(drops, tx)
1486+
continue
1487+
}
1488+
}
1489+
}
1490+
if doTrs {
1491+
if pool.trsListMap[addr] || (tx.To() != nil && pool.trsListMap[*tx.To()]) {
1492+
log.Trace("Removed queued transaction included in trsList", "hash", tx.Hash(), "addr", addr)
14351493
list.Remove(tx)
14361494
drops = append(drops, tx)
14371495
}
@@ -1637,13 +1695,25 @@ func (pool *TxPool) demoteUnexecutables() {
16371695
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
16381696
drops, invalids := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
16391697

1640-
// fee delegation
1641-
if pool.feedelegation {
1698+
// Add TRS
1699+
// Only nodes that subscribe to TRS removes transactions included in trsList.
1700+
doTrs := !metaminer.IsPoW() && len(pool.trsListMap) > 0 && pool.trsSubscribe
1701+
if pool.feedelegation || doTrs {
16421702
for _, tx := range list.Flatten() {
1643-
if tx.Type() == types.FeeDelegateDynamicFeeTxType && tx.FeePayer() != nil {
1644-
feePayer := *tx.FeePayer()
1645-
if pool.currentState.GetBalance(feePayer).Cmp(tx.FeePayerCost()) < 0 {
1646-
log.Trace("demoteUnexecutables", "hash", tx.Hash().String())
1703+
if pool.feedelegation {
1704+
if tx.Type() == types.FeeDelegateDynamicFeeTxType && tx.FeePayer() != nil {
1705+
feePayer := *tx.FeePayer()
1706+
if pool.currentState.GetBalance(feePayer).Cmp(tx.FeePayerCost()) < 0 {
1707+
log.Trace("Removed pending fee delegation transaction", "hash", tx.Hash().String())
1708+
list.Remove(tx)
1709+
drops = append(drops, tx)
1710+
continue
1711+
}
1712+
}
1713+
}
1714+
if doTrs {
1715+
if pool.trsListMap[addr] || (tx.To() != nil && pool.trsListMap[*tx.To()]) {
1716+
log.Trace("Removed pending transaction included in trsList", "hash", tx.Hash(), "addr", addr)
16471717
list.Remove(tx)
16481718
drops = append(drops, tx)
16491719
}

ethdb/rocksdb/rocksdb.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ func (it *RDBIterator) Next() bool {
272272
if it.first {
273273
it.first = false
274274
} else {
275+
// Added conditions to prevent Rocksdb Iterator error.
276+
// Valid() call is a RocksDB requirement.
277+
if C.rocksdb_iter_valid(it.it) == 0 {
278+
return false
279+
}
275280
C.rocksdb_iter_next(it.it)
276281
}
277282
return C.rocksdb_iter_valid(it.it) != 0

internal/web3ext/web3ext.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ web3._extend({
249249
call: 'admin_etcdDeleteWork',
250250
params: 0
251251
}),
252+
new web3._extend.Method({
253+
name: 'trsInfo',
254+
call: 'admin_trsInfo',
255+
params: 1,
256+
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
257+
}),
252258
],
253259
properties: [
254260
new web3._extend.Property({

light/txpool.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/ethdb"
3232
"github.com/ethereum/go-ethereum/event"
3333
"github.com/ethereum/go-ethereum/log"
34+
metaminer "github.com/ethereum/go-ethereum/metadium/miner"
3435
"github.com/ethereum/go-ethereum/params"
3536
)
3637

@@ -71,6 +72,9 @@ type TxPool struct {
7172
eip2718 bool // Fork indicator whether we are in the eip2718 stage.
7273
// fee delegation
7374
feedelegation bool // Fork indicator whether we are in the fee delegation stage.
75+
// Add TRS
76+
trsListMap map[common.Address]bool
77+
trsSubscribe bool
7478
}
7579

7680
// TxRelayBackend provides an interface to the mechanism that forwards transacions
@@ -322,6 +326,13 @@ func (pool *TxPool) setNewHead(head *types.Header) {
322326
pool.eip2718 = pool.config.IsBerlin(next)
323327
// fee delegation
324328
pool.feedelegation = pool.config.IsApplepie(next)
329+
// Add TRS
330+
if !metaminer.IsPoW() {
331+
pool.trsListMap, pool.trsSubscribe, _ = metaminer.GetTRSListMap(head.Number)
332+
} else {
333+
pool.trsListMap = nil
334+
pool.trsSubscribe = false
335+
}
325336
}
326337

327338
// Stop stops the light transaction pool
@@ -382,6 +393,16 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error
382393
return core.ErrNegativeValue
383394
}
384395

396+
// Add TRS
397+
// Only nodes that subscribe to TRS reject transactions included in trsList.
398+
if !metaminer.IsPoW() {
399+
if len(pool.trsListMap) > 0 && pool.trsSubscribe {
400+
if pool.trsListMap[from] || (tx.To() != nil && pool.trsListMap[*tx.To()]) {
401+
return core.ErrIncludedTRSList
402+
}
403+
}
404+
}
405+
385406
// Transactor should have enough funds to cover the costs
386407
// cost == V + GP * GL
387408

0 commit comments

Comments
 (0)