Compare commits

...

7 Commits

Author SHA1 Message Date
Elias Rad
b533bc0acb
Merge aa046be4b7 into 351c2cb132 2025-02-13 03:13:18 +01:00
Solovyov1796
351c2cb132
Merge pull request #110 from Solovyov1796/dev2
update suggestion gas price
2025-02-13 10:12:55 +08:00
Solovyov1796
6f83c22853 update ethermint version 2025-02-13 10:11:33 +08:00
Solovyov1796
4d95fd5f30 update suggestion gas price 2025-02-13 02:19:08 +08:00
Elias Rad
aa046be4b7
Update README.md 2025-01-25 13:29:05 +02:00
Elias Rad
c3e0379d45
Update Telemetry.md 2025-01-25 13:27:59 +02:00
Elias Rad
ed72e68773
Update proto-docs.md 2025-01-25 13:27:21 +02:00
11 changed files with 21 additions and 160 deletions

View File

@ -27,9 +27,9 @@ Continue reading [here](https://docs.0g.ai/intro) if you want to learn more abou
## Support and Additional Resources ## Support and Additional Resources
We want to do everything we can to help you be successful while working on your contribution and projects. Here you'll find various resources and communities that may help you complete a project or contribute to 0G. We want to do everything we can to help you be successful while working on your contributions and projects. Here you'll find various resources and communities that may help you complete a project or contribute to 0G.
### Communities ### Communities
- [0G Telegram](https://t.me/web3_0glabs) - [0G Telegram](https://t.me/web3_0glabs)
- [0G Discord](https://discord.com/invite/0glabs) - [0G Discord](https://discord.com/invite/0glabs)

View File

@ -2,10 +2,7 @@ package app
import ( import (
"fmt" "fmt"
"math/big"
"sort"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/cockroachdb/errors" "github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types" abci "github.com/cometbft/cometbft/abci/types"
gethtypes "github.com/ethereum/go-ethereum/core/types" gethtypes "github.com/ethereum/go-ethereum/core/types"
@ -16,8 +13,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing"
) )
const gasPriceSuggestionBlockNum int64 = 5
type ( type (
// GasTx defines the contract that a transaction with a gas limit must implement. // GasTx defines the contract that a transaction with a gas limit must implement.
GasTx interface { GasTx interface {
@ -35,29 +30,17 @@ type (
// DefaultProposalHandler defines the default ABCI PrepareProposal and // DefaultProposalHandler defines the default ABCI PrepareProposal and
// ProcessProposal handlers. // ProcessProposal handlers.
DefaultProposalHandler struct { DefaultProposalHandler struct {
mempool mempool.Mempool mempool mempool.Mempool
txVerifier ProposalTxVerifier txVerifier ProposalTxVerifier
txSelector TxSelector txSelector TxSelector
feemarketKeeper FeeMarketKeeper
}
FeeMarketKeeper interface {
SetSuggestionGasPrice(ctx sdk.Context, gas *big.Int)
}
txnInfo struct {
gasPrice *big.Int
gasLimit uint64
nonce uint64
sender string
} }
) )
func NewDefaultProposalHandler(mp mempool.Mempool, txVerifier ProposalTxVerifier, feemarketKeeper FeeMarketKeeper) *DefaultProposalHandler { func NewDefaultProposalHandler(mp mempool.Mempool, txVerifier ProposalTxVerifier) *DefaultProposalHandler {
return &DefaultProposalHandler{ return &DefaultProposalHandler{
mempool: mp, mempool: mp,
txVerifier: txVerifier, txVerifier: txVerifier,
txSelector: NewDefaultTxSelector(), txSelector: NewDefaultTxSelector(),
feemarketKeeper: feemarketKeeper,
} }
} }
@ -114,14 +97,11 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
return abci.ResponsePrepareProposal{Txs: h.txSelector.SelectedTxs()} return abci.ResponsePrepareProposal{Txs: h.txSelector.SelectedTxs()}
} }
txnInfoMap := make(map[string][]*txnInfo, h.mempool.CountTx())
iterator := h.mempool.Select(ctx, req.Txs) iterator := h.mempool.Select(ctx, req.Txs)
selectedTxsSignersSeqs := make(map[string]uint64) selectedTxsSignersSeqs := make(map[string]uint64)
var selectedTxsNums int var selectedTxsNums int
for iterator != nil { for iterator != nil {
memTx := iterator.Tx() memTx := iterator.Tx()
sigs, err := memTx.(signing.SigVerifiableTx).GetSignaturesV2() sigs, err := memTx.(signing.SigVerifiableTx).GetSignaturesV2()
if err != nil { if err != nil {
panic(fmt.Errorf("failed to get signatures: %w", err)) panic(fmt.Errorf("failed to get signatures: %w", err))
@ -154,42 +134,10 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
txSignersSeqs[signer] = nonce txSignersSeqs[signer] = nonce
} }
} }
if _, exists := txnInfoMap[signer]; !exists {
txnInfoMap[signer] = make([]*txnInfo, 0, 128)
}
txnInfoMap[signer] = append(txnInfoMap[signer], &txnInfo{
gasPrice: ethTx.GasPrice(),
gasLimit: ethTx.Gas(),
nonce: nonce,
sender: signer,
})
} }
} }
} }
} else { } else {
// ignore multisig case now
fee := memTx.(sdk.Fee)
if len(sigs) == 1 {
signer := sdk.AccAddress(sigs[0].PubKey.Address()).String()
if _, exists := txnInfoMap[signer]; !exists {
txnInfoMap[signer] = make([]*txnInfo, 0, 16)
}
evmGasPrice, err := utilCosmosDemonGasPriceToEvmDemonGasPrice(fee.GetAmount())
if err == nil {
txnInfoMap[signer] = append(txnInfoMap[signer], &txnInfo{
gasPrice: evmGasPrice,
gasLimit: utilCosmosDemonGasLimitToEvmDemonGasLimit(fee.GetGas()),
nonce: sigs[0].Sequence,
sender: signer,
})
}
}
for _, sig := range sigs { for _, sig := range sigs {
signer := sdk.AccAddress(sig.PubKey.Address()).String() signer := sdk.AccAddress(sig.PubKey.Address()).String()
seq, ok := selectedTxsSignersSeqs[signer] seq, ok := selectedTxsSignersSeqs[signer]
@ -250,65 +198,6 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
iterator = iterator.Next() iterator = iterator.Next()
} }
if len(txnInfoMap) == 0 {
h.feemarketKeeper.SetSuggestionGasPrice(ctx, big.NewInt(0))
} else {
senderCnt := 0
txnCnt := 0
for sender := range txnInfoMap {
sort.Slice(txnInfoMap[sender], func(i, j int) bool {
return txnInfoMap[sender][i].nonce < txnInfoMap[sender][j].nonce
})
txnCnt += len(txnInfoMap[sender])
senderCnt++
}
remaing := gasPriceSuggestionBlockNum * int64(maxBlockGas)
var lastProcessedTx *txnInfo
for remaing > 0 && len(txnInfoMap) > 0 {
// Find the highest gas price among the first transaction of each account
var highestGasPrice *big.Int
var selectedSender string
// Compare first transaction (lowest nonce) from each account
for sender, txns := range txnInfoMap {
if len(txns) == 0 {
delete(txnInfoMap, sender)
continue
}
// First tx has lowest nonce due to earlier sorting
if highestGasPrice == nil || txns[0].gasPrice.Cmp(highestGasPrice) > 0 {
highestGasPrice = txns[0].gasPrice
selectedSender = sender
}
}
if selectedSender == "" {
break
}
// Process the selected transaction
selectedTx := txnInfoMap[selectedSender][0]
remaing -= int64(selectedTx.gasLimit)
lastProcessedTx = selectedTx
// Remove processed transaction
txnInfoMap[selectedSender] = txnInfoMap[selectedSender][1:]
if len(txnInfoMap[selectedSender]) == 0 {
delete(txnInfoMap, selectedSender)
}
}
if lastProcessedTx != nil && remaing <= 0 {
h.feemarketKeeper.SetSuggestionGasPrice(ctx, lastProcessedTx.gasPrice)
} else {
h.feemarketKeeper.SetSuggestionGasPrice(ctx, big.NewInt(0))
}
}
return abci.ResponsePrepareProposal{Txs: h.txSelector.SelectedTxs()} return abci.ResponsePrepareProposal{Txs: h.txSelector.SelectedTxs()}
} }
} }
@ -447,22 +336,3 @@ func (ts *defaultTxSelector) SelectTxForProposal(maxTxBytes, maxBlockGas uint64,
// check if we've reached capacity; if so, we cannot select any more transactions // check if we've reached capacity; if so, we cannot select any more transactions
return ts.totalTxBytes >= maxTxBytes || (maxBlockGas > 0 && (ts.totalTxGas >= maxBlockGas)) return ts.totalTxBytes >= maxTxBytes || (maxBlockGas > 0 && (ts.totalTxGas >= maxBlockGas))
} }
func utilCosmosDemonGasPriceToEvmDemonGasPrice(gasGroup sdk.Coins) (*big.Int, error) {
gasPrice := big.NewInt(0)
for _, coin := range gasGroup {
if coin.Denom == chaincfg.GasDenom {
thisGasPrice := big.NewInt(0).SetUint64(coin.Amount.Uint64())
thisGasPrice = thisGasPrice.Mul(thisGasPrice, big.NewInt(0).SetInt64(chaincfg.GasDenomConversionMultiplier))
gasPrice = gasPrice.Add(gasPrice, thisGasPrice)
} else {
return big.NewInt(0), fmt.Errorf("invalid denom: %s", coin.Denom)
}
}
return gasPrice, nil
}
func utilCosmosDemonGasLimitToEvmDemonGasLimit(gasLimit uint64) uint64 {
return gasLimit * chaincfg.GasDenomConversionMultiplier
}

View File

@ -62,7 +62,6 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
encodingConfig, encodingConfig,
baseapp.SetChainID(app.TestChainId), baseapp.SetChainID(app.TestChainId),
), ),
nil,
), ),
} }

View File

@ -313,7 +313,6 @@ func NewApp(
encodingConfig chainparams.EncodingConfig, encodingConfig chainparams.EncodingConfig,
options Options, options Options,
bApp *baseapp.BaseApp, bApp *baseapp.BaseApp,
setAbciProposalHandler func(feemarketKeeper FeeMarketKeeper) sdk.PrepareProposalHandler,
) *App { ) *App {
appCodec := encodingConfig.Marshaler appCodec := encodingConfig.Marshaler
legacyAmino := encodingConfig.Amino legacyAmino := encodingConfig.Amino
@ -490,6 +489,7 @@ func NewApp(
keys[feemarkettypes.StoreKey], keys[feemarkettypes.StoreKey],
tkeys[feemarkettypes.TransientKey], tkeys[feemarkettypes.TransientKey],
feemarketSubspace, feemarketSubspace,
bApp.Mempool(),
) )
app.evmutilKeeper = evmutilkeeper.NewKeeper( app.evmutilKeeper = evmutilkeeper.NewKeeper(
@ -902,10 +902,6 @@ func NewApp(
app.SetBeginBlocker(app.BeginBlocker) app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker) app.SetEndBlocker(app.EndBlocker)
if setAbciProposalHandler != nil {
abciProposalHandler := setAbciProposalHandler(app.feeMarketKeeper)
bApp.SetPrepareProposal(abciProposalHandler)
}
// load store // load store
if !options.SkipLoadLatest { if !options.SkipLoadLatest {
if err := app.LoadLatestVersion(); err != nil { if err := app.LoadLatestVersion(); err != nil {

View File

@ -38,7 +38,6 @@ func TestNewApp(t *testing.T) {
MakeEncodingConfig(), MakeEncodingConfig(),
baseapp.SetChainID(TestChainId), baseapp.SetChainID(TestChainId),
), ),
nil,
) )
} }
@ -56,7 +55,6 @@ func TestExport(t *testing.T) {
MakeEncodingConfig(), MakeEncodingConfig(),
baseapp.SetChainID(TestChainId), baseapp.SetChainID(TestChainId),
), ),
nil,
) )
genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState()) genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState())

View File

@ -96,7 +96,7 @@ func NewTestAppFromSealed() TestApp {
bApp := NewBaseApp(log.NewNopLogger(), db, encCfg, baseapp.SetChainID(TestChainId)) bApp := NewBaseApp(log.NewNopLogger(), db, encCfg, baseapp.SetChainID(TestChainId))
app := NewApp( app := NewApp(
chaincfg.DefaultNodeHome, nil, chaincfg.DefaultNodeHome, nil,
encCfg, DefaultOptions, bApp, nil, encCfg, DefaultOptions, bApp,
) )
return TestApp{App: *app} return TestApp{App: *app}
} }

View File

@ -126,6 +126,8 @@ func (ac appCreator) newApp(
baseapp.SetMempool(mempool), baseapp.SetMempool(mempool),
) )
bApp.SetTxEncoder(ac.encodingConfig.TxConfig.TxEncoder()) bApp.SetTxEncoder(ac.encodingConfig.TxConfig.TxEncoder())
abciProposalHandler := app.NewDefaultProposalHandler(mempool, bApp)
bApp.SetPrepareProposal(abciProposalHandler.PrepareProposalHandler())
newApp := app.NewApp( newApp := app.NewApp(
homeDir, traceStore, ac.encodingConfig, homeDir, traceStore, ac.encodingConfig,
@ -140,10 +142,6 @@ func (ac appCreator) newApp(
EVMMaxGasWanted: cast.ToUint64(appOpts.Get(ethermintflags.EVMMaxTxGasWanted)), EVMMaxGasWanted: cast.ToUint64(appOpts.Get(ethermintflags.EVMMaxTxGasWanted)),
}, },
bApp, bApp,
func(k app.FeeMarketKeeper) sdk.PrepareProposalHandler {
abciProposalHandler := app.NewDefaultProposalHandler(mempool, bApp, k)
return abciProposalHandler.PrepareProposalHandler()
},
) )
return newApp return newApp
@ -172,14 +170,14 @@ func (ac appCreator) appExport(
var tempApp *app.App var tempApp *app.App
if height != -1 { if height != -1 {
bApp := app.NewBaseApp(logger, db, ac.encodingConfig) bApp := app.NewBaseApp(logger, db, ac.encodingConfig)
tempApp = app.NewApp(homePath, traceStore, ac.encodingConfig, options, bApp, nil) tempApp = app.NewApp(homePath, traceStore, ac.encodingConfig, options, bApp)
if err := tempApp.LoadHeight(height); err != nil { if err := tempApp.LoadHeight(height); err != nil {
return servertypes.ExportedApp{}, err return servertypes.ExportedApp{}, err
} }
} else { } else {
bApp := app.NewBaseApp(logger, db, ac.encodingConfig) bApp := app.NewBaseApp(logger, db, ac.encodingConfig)
tempApp = app.NewApp(homePath, traceStore, ac.encodingConfig, options, bApp, nil) tempApp = app.NewApp(homePath, traceStore, ac.encodingConfig, options, bApp)
} }
return tempApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) return tempApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
} }

View File

@ -4,7 +4,7 @@
## Enabling Kava Metric Telemetry ## Enabling Kava Metric Telemetry
To enable the kava app to emit telemetry during operation, update the relevant config values to enable metrics: To enable the Kava app to emit telemetry during operation, update the relevant config values to enable metrics:
`config.toml` `config.toml`
@ -65,7 +65,7 @@ Update [prometheus config](../prometheus.yml) to collect metrics from your local
### Collecting from remote host ### Collecting from remote host
Update the kava config on the host and restart using the instructions from `Enabling Kava Metric Emission` Update the Kava config on the host and restart using the instructions from `Enabling Kava Metric Emission`
Install [ngrok](https://ngrok.com/download) on the remote host Install [ngrok](https://ngrok.com/download) on the remote host

View File

@ -2671,7 +2671,7 @@ GenesisState defines the council module's genesis state.
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| `params` | [Params](#kava.community.v1beta1.Params) | | params defines all the parameters related to commmunity | | `params` | [Params](#kava.community.v1beta1.Params) | | params defines all the parameters related to community |
| `staking_rewards_state` | [StakingRewardsState](#kava.community.v1beta1.StakingRewardsState) | | StakingRewardsState stores the internal staking reward data required to track staking rewards across blocks | | `staking_rewards_state` | [StakingRewardsState](#kava.community.v1beta1.StakingRewardsState) | | StakingRewardsState stores the internal staking reward data required to track staking rewards across blocks |

2
go.mod
View File

@ -250,7 +250,7 @@ replace (
// TODO: Tag before release // TODO: Tag before release
github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc2 github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc2
// Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support // Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support
github.com/evmos/ethermint => github.com/0glabs/ethermint v0.21.0-0g.v3.1.10 github.com/evmos/ethermint => github.com/0glabs/ethermint v0.21.0-0g.v3.1.12
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320 // See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
// Downgraded to avoid bugs in following commits which causes "version does not exist" errors // Downgraded to avoid bugs in following commits which causes "version does not exist" errors

4
go.sum
View File

@ -213,8 +213,8 @@ github.com/0glabs/cometbft v0.37.9-0glabs.1 h1:KQJG17Y21suKP3QNICLto4b5Ak73XbSmK
github.com/0glabs/cometbft v0.37.9-0glabs.1/go.mod h1:j0Q3RqrCd+cztWCugs3obbzC4NyHGBPZZjtm/fWV00I= github.com/0glabs/cometbft v0.37.9-0glabs.1/go.mod h1:j0Q3RqrCd+cztWCugs3obbzC4NyHGBPZZjtm/fWV00I=
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.10 h1:NJp0RwczHBO4EvrQdDxxftHOgUDBtNh7M/vpaG7wFtQ= github.com/0glabs/cosmos-sdk v0.47.10-0glabs.10 h1:NJp0RwczHBO4EvrQdDxxftHOgUDBtNh7M/vpaG7wFtQ=
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.10/go.mod h1:KskIVnhXTFqrw7CDccMvx7To5KzUsOomIsQV7sPGOog= github.com/0glabs/cosmos-sdk v0.47.10-0glabs.10/go.mod h1:KskIVnhXTFqrw7CDccMvx7To5KzUsOomIsQV7sPGOog=
github.com/0glabs/ethermint v0.21.0-0g.v3.1.10 h1:DE8hK2OJp9rKYdT2Y0G259/6nAFcOQi383l2e7/VFnE= github.com/0glabs/ethermint v0.21.0-0g.v3.1.12 h1:IRVTFhDEH2J5w8ywQW7obXQxYhJYib70SNgKqLOXikU=
github.com/0glabs/ethermint v0.21.0-0g.v3.1.10/go.mod h1:6e/gOcDLhvlDWK3JLJVBgki0gD6H4E1eG7l9byocgWA= github.com/0glabs/ethermint v0.21.0-0g.v3.1.12/go.mod h1:6e/gOcDLhvlDWK3JLJVBgki0gD6H4E1eG7l9byocgWA=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=