Skip to content

Commit 7b9d105

Browse files
authored
Merge pull request #2 from node-real/netmarble_v2.0_dev
Fncy2 demand development
2 parents 443e3d8 + de8b3dd commit 7b9d105

File tree

9 files changed

+1391
-583
lines changed

9 files changed

+1391
-583
lines changed

consensus/parlia/abi.go

Lines changed: 1045 additions & 538 deletions
Large diffs are not rendered by default.

consensus/parlia/parlia.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,9 @@ func (p *Parlia) getCurrentValidators(blockHash common.Hash) ([]common.Address,
10541054
}
10551055
func (p *Parlia) BlockRewards(blockNumber *big.Int) *big.Int {
10561056
if rules := p.chainConfig.Rules(blockNumber); rules.HasBlockRewards {
1057+
if p.chainConfig.Parlia.StopMintBlock != nil && p.chainConfig.Parlia.StopMintBlock.Cmp(blockNumber) <= 0 {
1058+
return nil
1059+
}
10571060
blockRewards := p.chainConfig.Parlia.BlockRewards
10581061
if blockRewards != nil && blockRewards.Cmp(common.Big0) > 0 {
10591062
return blockRewards
@@ -1070,17 +1073,20 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he
10701073
state.SetBalance(consensus.SystemAddress, big.NewInt(0))
10711074
state.AddBalance(coinbase, balance)
10721075
rewards := big.NewInt(0).Abs(balance)
1073-
if rules := p.chainConfig.Rules(header.Number); rules.HasBlockRewards {
1074-
blockRewards := p.chainConfig.Parlia.BlockRewards
1075-
// if we have enabled block rewards and rewards are greater than 0 then
1076-
if blockRewards != nil && blockRewards.Cmp(common.Big0) > 0 {
1077-
state.AddBalance(coinbase, blockRewards)
1078-
rewards = rewards.Add(rewards, blockRewards)
1079-
}
1076+
blockRewards := p.BlockRewards(header.Number)
1077+
if blockRewards != nil {
1078+
rewards = rewards.Add(rewards, blockRewards)
1079+
state.AddBalance(coinbase, blockRewards)
10801080
}
10811081
if rewards.Cmp(common.Big0) <= 0 {
10821082
return nil
10831083
}
1084+
if p.chainConfig.IsFncy2(header.Number) {
1085+
if blockRewards == nil {
1086+
blockRewards = big.NewInt(0)
1087+
}
1088+
return p.distributeRewards(rewards, blockRewards, balance, val, state, header, chain, txs, receipts, receivedTxs, usedGas, mining)
1089+
}
10841090
// remove 1/16 reward according to netmarble
10851091
//doDistributeSysReward := state.GetBalance(common.HexToAddress(systemcontract.SystemRewardContract)).Cmp(maxSystemBalance) < 0
10861092
//if doDistributeSysReward {
@@ -1160,6 +1166,27 @@ func (p *Parlia) distributeToSystem(amount *big.Int, state *state.StateDB, heade
11601166
return p.applyTransaction(msg, state, header, chain, txs, receipts, receivedTxs, usedGas, mining)
11611167
}
11621168

1169+
// slash spoiled validators
1170+
func (p *Parlia) distributeRewards(amount *big.Int, blockRewards *big.Int, gasFee *big.Int, validator common.Address,
1171+
state *state.StateDB, header *types.Header, chain core.ChainContext,
1172+
txs *[]*types.Transaction, receipts *[]*types.Receipt, receivedTxs *[]*types.Transaction, usedGas *uint64, mining bool) error {
1173+
// method
1174+
method := "distributeRewards"
1175+
1176+
// get packed data
1177+
data, err := p.validatorSetABI.Pack(method,
1178+
validator, blockRewards, gasFee,
1179+
)
1180+
if err != nil {
1181+
log.Error("Unable to pack tx for distributeRewards", "error", err)
1182+
return err
1183+
}
1184+
// get system message
1185+
msg := p.getSystemMessage(header.Coinbase, common.HexToAddress(systemcontract.ValidatorContract), data, amount)
1186+
// apply message
1187+
return p.applyTransaction(msg, state, header, chain, txs, receipts, receivedTxs, usedGas, mining)
1188+
}
1189+
11631190
// slash spoiled validators
11641191
func (p *Parlia) distributeToValidator(amount *big.Int, validator common.Address,
11651192
state *state.StateDB, header *types.Header, chain core.ChainContext,

core/tx_pool.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ type TxPool struct {
253253

254254
gasFreeAddressMap map[common.Address]uint // from address that can join tx_pool for free
255255
gasFreeAddressMapFunc func(common.Hash) (map[common.Address]uint, error) // add func to get gasFreeAddressMap
256+
gasPriceFunc func(common.Hash) (*big.Int, error) // add func to get gas price, do nothing when return 0
256257

257258
pending map[common.Address]*txList // All currently processable transactions
258259
queue map[common.Address]*txList // Queued but non-processable transactions
@@ -283,11 +284,17 @@ func getNoGasFreeAddressMapFunc() func(common.Hash) (map[common.Address]uint, er
283284
return gasFreeToAddressMap, nil
284285
}
285286
}
287+
func getGasPriceFunc() func(common.Hash) (*big.Int, error) {
288+
return func(blockHash common.Hash) (*big.Int, error) {
289+
return big.NewInt(0), nil
290+
}
291+
}
292+
286293
func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain blockChain) *TxPool {
287294

288-
return NewEnhanceTxPool(config, chainconfig, chain, getNoGasFreeAddressMapFunc())
295+
return NewEnhanceTxPool(config, chainconfig, chain, getNoGasFreeAddressMapFunc(), getGasPriceFunc())
289296
}
290-
func NewEnhanceTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain blockChain, gasFreeAddressMapFunc func(common.Hash) (map[common.Address]uint, error)) *TxPool {
297+
func NewEnhanceTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain blockChain, gasFreeAddressMapFunc func(common.Hash) (map[common.Address]uint, error), gasPriceFunc func(common.Hash) (*big.Int, error)) *TxPool {
291298
// Sanitize the input to ensure no vulnerable gas prices are set
292299
config = (&config).sanitize()
293300
// Create the transaction pool with its initial settings
@@ -309,6 +316,7 @@ func NewEnhanceTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chai
309316
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
310317
gasFreeAddressMap: make(map[common.Address]uint),
311318
gasFreeAddressMapFunc: gasFreeAddressMapFunc,
319+
gasPriceFunc: gasPriceFunc,
312320
}
313321
pool.locals = newAccountSet(pool.signer)
314322
for _, addr := range config.Locals {
@@ -479,10 +487,19 @@ func (pool *TxPool) SubscribeReannoTxsEvent(ch chan<- ReannoTxsEvent) event.Subs
479487
func (pool *TxPool) GasPrice() *big.Int {
480488
pool.mu.RLock()
481489
defer pool.mu.RUnlock()
490+
return new(big.Int).Set(pool.gasPrice)
491+
}
482492

493+
//Fncy2 Update
494+
func (pool *TxPool) GasPriceWithoutLock() *big.Int {
483495
return new(big.Int).Set(pool.gasPrice)
484496
}
485497

498+
func (pool *TxPool) SetGasPriceWithoutLock(price *big.Int) {
499+
pool.gasPrice = price
500+
log.Info("Transaction pool price threshold updated", "price", price)
501+
}
502+
486503
// SetGasPrice updates the minimum price required by the transaction pool for a
487504
// new transaction, and drops all transactions below this threshold.
488505
func (pool *TxPool) SetGasPrice(price *big.Int) {
@@ -551,7 +568,6 @@ func (pool *TxPool) Content() (map[common.Address]types.Transactions, map[common
551568
func (pool *TxPool) Pending() (map[common.Address]types.Transactions, error) {
552569
pool.mu.Lock()
553570
defer pool.mu.Unlock()
554-
555571
pending := make(map[common.Address]types.Transactions)
556572
for addr, list := range pool.pending {
557573
pending[addr] = list.Flatten()
@@ -1293,6 +1309,21 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
12931309
next := new(big.Int).Add(newHead.Number, big.NewInt(1))
12941310
pool.istanbul = pool.chainconfig.IsIstanbul(next)
12951311
pool.eip2718 = pool.chainconfig.IsBerlin(next)
1312+
//fncy2 update
1313+
if pool.chainconfig.IsFncy2(next) {
1314+
gasPrice, err := pool.gasPriceFunc(pool.chain.CurrentBlock().Hash())
1315+
if err != nil {
1316+
log.Warn("Failed to get gasPrice", "err", err)
1317+
} else {
1318+
if gasPrice != nil && gasPrice.Cmp(common.Big0) > 0 {
1319+
if pool.gasPrice.Cmp(gasPrice) != 0 {
1320+
log.Debug("Set gasPrice ", " old gasPrice", pool.gasPrice, " new gasPrice", gasPrice)
1321+
pool.SetGasPriceWithoutLock(gasPrice)
1322+
}
1323+
}
1324+
}
1325+
}
1326+
12961327
}
12971328

12981329
// promoteExecutables moves transactions that have become processable from the

core/vm/evm.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,11 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
515515
ret, err := run(evm, contract, nil, false)
516516

517517
// Check whether the max code size has been exceeded, assign err if the case.
518-
if err == nil && evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize {
518+
maxCodeSize := params.MaxCodeSize
519+
if evm.chainRules.IsContract48kBlock {
520+
maxCodeSize = params.MaxCodeSize * 2
521+
}
522+
if err == nil && evm.chainRules.IsEIP158 && len(ret) > maxCodeSize {
519523
err = ErrMaxCodeSizeExceeded
520524
}
521525

eth/abi.go

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ const chainConfigABI = `
2121
"name": "ActiveValidatorsLengthChanged",
2222
"type": "event"
2323
},
24+
{
25+
"anonymous": false,
26+
"inputs": [
27+
{
28+
"indexed": false,
29+
"internalType": "address",
30+
"name": "account",
31+
"type": "address"
32+
},
33+
{
34+
"indexed": false,
35+
"internalType": "uint16",
36+
"name": "share",
37+
"type": "uint16"
38+
}
39+
],
40+
"name": "DistributeRewardsShareChanged",
41+
"type": "event"
42+
},
2443
{
2544
"anonymous": false,
2645
"inputs": [
@@ -78,6 +97,25 @@ const chainConfigABI = `
7897
"name": "FelonyThresholdChanged",
7998
"type": "event"
8099
},
100+
{
101+
"anonymous": false,
102+
"inputs": [
103+
{
104+
"indexed": false,
105+
"internalType": "address",
106+
"name": "preValue",
107+
"type": "address"
108+
},
109+
{
110+
"indexed": false,
111+
"internalType": "address",
112+
"name": "newValue",
113+
"type": "address"
114+
}
115+
],
116+
"name": "FoundationAddressChanged",
117+
"type": "event"
118+
},
81119
{
82120
"anonymous": false,
83121
"inputs": [
@@ -142,6 +180,25 @@ const chainConfigABI = `
142180
"name": "FreeGasAddressSizeChanged",
143181
"type": "event"
144182
},
183+
{
184+
"anonymous": false,
185+
"inputs": [
186+
{
187+
"indexed": false,
188+
"internalType": "uint256",
189+
"name": "preValue",
190+
"type": "uint256"
191+
},
192+
{
193+
"indexed": false,
194+
"internalType": "uint256",
195+
"name": "newValue",
196+
"type": "uint256"
197+
}
198+
],
199+
"name": "GasPriceChanged",
200+
"type": "event"
201+
},
145202
{
146203
"anonymous": false,
147204
"inputs": [
@@ -250,6 +307,19 @@ const chainConfigABI = `
250307
"name": "ValidatorJailEpochLengthChanged",
251308
"type": "event"
252309
},
310+
{
311+
"anonymous": false,
312+
"inputs": [
313+
{
314+
"indexed": false,
315+
"internalType": "uint16",
316+
"name": "share",
317+
"type": "uint16"
318+
}
319+
],
320+
"name": "ValidatorRewardsShareChanged",
321+
"type": "event"
322+
},
253323
{
254324
"inputs": [],
255325
"name": "freeGasAddressAdmin",
@@ -711,6 +781,111 @@ const chainConfigABI = `
711781
"outputs": [],
712782
"stateMutability": "nonpayable",
713783
"type": "function"
784+
},
785+
{
786+
"inputs": [
787+
{
788+
"internalType": "uint256",
789+
"name": "newValue",
790+
"type": "uint256"
791+
}
792+
],
793+
"name": "setGasPrice",
794+
"outputs": [],
795+
"stateMutability": "nonpayable",
796+
"type": "function"
797+
},
798+
{
799+
"inputs": [],
800+
"name": "getGasPrice",
801+
"outputs": [
802+
{
803+
"internalType": "uint256",
804+
"name": "",
805+
"type": "uint256"
806+
}
807+
],
808+
"stateMutability": "view",
809+
"type": "function"
810+
},
811+
{
812+
"inputs": [],
813+
"name": "getDistributeRewardsShares",
814+
"outputs": [
815+
{
816+
"internalType": "uint16",
817+
"name": "",
818+
"type": "uint16"
819+
},
820+
{
821+
"components": [
822+
{
823+
"internalType": "address",
824+
"name": "account",
825+
"type": "address"
826+
},
827+
{
828+
"internalType": "uint16",
829+
"name": "share",
830+
"type": "uint16"
831+
}
832+
],
833+
"internalType": "struct IChainConfig.DistributeRewardsShare[]",
834+
"name": "",
835+
"type": "tuple[]"
836+
}
837+
],
838+
"stateMutability": "view",
839+
"type": "function"
840+
},
841+
{
842+
"inputs": [
843+
{
844+
"internalType": "uint16",
845+
"name": "validatorShare",
846+
"type": "uint16"
847+
},
848+
{
849+
"internalType": "address[]",
850+
"name": "accounts",
851+
"type": "address[]"
852+
},
853+
{
854+
"internalType": "uint16[]",
855+
"name": "shares",
856+
"type": "uint16[]"
857+
}
858+
],
859+
"name": "updateDistributeRewardsShares",
860+
"outputs": [],
861+
"stateMutability": "nonpayable",
862+
"type": "function"
863+
},
864+
{
865+
"inputs": [
866+
{
867+
"internalType": "address",
868+
"name": "newValue",
869+
"type": "address"
870+
}
871+
],
872+
"name": "setFoundationAddress",
873+
"outputs": [],
874+
"stateMutability": "nonpayable",
875+
"type": "function"
876+
},
877+
{
878+
"inputs": [],
879+
"name": "getFoundationAddress",
880+
"outputs": [
881+
{
882+
"internalType": "address",
883+
"name": "",
884+
"type": "address"
885+
}
886+
],
887+
"stateMutability": "view",
888+
"type": "function"
714889
}
715890
]
716891
`

eth/api_backend.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ func (b *EthAPIBackend) Downloader() *downloader.Downloader {
276276
}
277277

278278
func (b *EthAPIBackend) SuggestPrice(ctx context.Context) (*big.Int, error) {
279+
//Fncy2 Update
280+
if b.ChainConfig().IsFncy2(b.Chain().CurrentBlock().Header().Number) {
281+
suggestPrice, err := b.gpo.SuggestPrice(ctx)
282+
if err != nil {
283+
gasprice := b.eth.TxPool().GasPriceWithoutLock()
284+
if suggestPrice.Cmp(gasprice) < 0 {
285+
return gasprice, nil
286+
}
287+
}
288+
}
279289
return b.gpo.SuggestPrice(ctx)
280290
}
281291

0 commit comments

Comments
 (0)