Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activate pbss as experimental feature #137

Draft
wants to merge 26 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/ante/EthGasConsumeDecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
}

gasLimit := msgEthTx.GetGas()
gas, err := ethcore.IntrinsicGas(msgEthTx.Data.Payload, []ethtypes.AccessTuple{}, msgEthTx.To() == nil, true, false)
gas, err := ethcore.IntrinsicGas(msgEthTx.Data.Payload, []ethtypes.AccessTuple{}, msgEthTx.To() == nil, true, false, false)
if err != nil {
return ctx, sdkerrors.Wrap(err, "failed to compute intrinsic gas cost")
}
Expand Down
2 changes: 1 addition & 1 deletion app/ante/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func ethGasConsume(ek EVMKeeper, ak accountKeeperInterface, sk types.SupplyKeepe
gasLimit := msgEthTx.GetGas()

if shouldIntrinsicGas(ek, ctx, msgEthTx) {
gas, err := ethcore.IntrinsicGas(msgEthTx.Data.Payload, []ethtypes.AccessTuple{}, msgEthTx.To() == nil, true, false)
gas, err := ethcore.IntrinsicGas(msgEthTx.Data.Payload, []ethtypes.AccessTuple{}, msgEthTx.To() == nil, true, false, false)
if err != nil {
return sdkerrors.Wrap(err, "failed to compute intrinsic gas cost")
}
Expand Down
2 changes: 2 additions & 0 deletions app/repair_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ func createAndStartProxyAppConns(clientCreator proxy.ClientCreator) (proxy.AppCo
}

func (app *repairApp) Close() {
app.StopBaseApp()

indexer := evmtypes.GetIndexer()
if indexer != nil {
for indexer.IsProcessing() {
Expand Down
6 changes: 3 additions & 3 deletions app/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import (
"sync"
"time"

"github.com/okx/okbchain/libs/cosmos-sdk/store/mpt"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rpc"
lru "github.com/hashicorp/golang-lru"
"github.com/okx/okbchain/libs/cosmos-sdk/store/mpt"
"github.com/spf13/viper"

appconfig "github.com/okx/okbchain/app/config"
Expand Down Expand Up @@ -1667,7 +1667,7 @@ func (api *PublicEthereumAPI) saveZeroAccount(address common.Address) {
api.watcherBackend.CommitAccountToRpcDb(zeroAccount)
}

func (api *PublicEthereumAPI) FeeHistory(blockCount rpc.DecimalOrHex, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*rpctypes.FeeHistoryResult, error) {
func (api *PublicEthereumAPI) FeeHistory(blockCount math.HexOrDecimal64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*rpctypes.FeeHistoryResult, error) {
api.logger.Debug("eth_feeHistory")
return nil, fmt.Errorf("unsupported rpc function: eth_FeeHistory")
}
Expand Down
2 changes: 1 addition & 1 deletion app/rpc/namespaces/eth/simulation/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func initCommitMultiStore(storeKey *sdk.KVStoreKey) (sdk.CommitMultiStore, *sdk.
cms.MountStoreWithDB(paramsKey, sdk.StoreTypeIAVL, db)
cms.MountStoreWithDB(storeKey, sdk.StoreTypeMPT, db)
cms.MountStoreWithDB(paramsTKey, sdk.StoreTypeTransient, db)
cms.LoadLatestVersion()
//cms.LoadLatestVersion() // for node restart panic: missing trie node
return cms, paramsKey, paramsTKey
}

Expand Down
7 changes: 6 additions & 1 deletion cmd/okbchaind/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,12 @@ func pruneMpt() {
hhash := sdk.Uint64ToBigEndian(latestHeight)
rootHashValue, err := accMptDb.TrieDB().DiskDB().Get(append(mpt.KeyPrefixAccRootMptHash, hhash...))
rootHash := ethcmn.BytesToHash(rootHashValue)
p, err := pruner.NewPrunerCustom(mpt.GetEthDB(), "", "", 256, rootHash, base.AccountStateRootRetriever{})
prunerconfig := pruner.Config{
Datadir: "",
Cachedir: "",
BloomSize: 256,
}
p, err := pruner.NewPrunerCustom(mpt.GetEthDB(), prunerconfig, rootHash, base.AccountStateRootRetriever{})
panicError(err)
log.Printf("Prune mpt %v...\n", rootHash.String())
err = p.Prune(rootHash)
Expand Down
11 changes: 5 additions & 6 deletions cmd/okbchaind/mpt/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,22 @@ func openApplicationDb(rootdir string) tmdb.DB {
*/
// getStorageTrie returns the trie of the given address and stateRoot
func getStorageTrie(db ethstate.Database, addrHash, stateRoot ethcmn.Hash) ethstate.Trie {
tr, err := db.OpenStorageTrie(addrHash, stateRoot)
tr, err := db.OpenStorageTrie(ethcmn.Hash{}, addrHash, stateRoot)
panicError(err)
return tr
}

// pushData2Database commit the data to the database
func pushData2Database(db ethstate.Database, tree ethstate.Trie, height int64, isEvm bool, nodes *trie.MergedNodeSet) {

root, set, err := tree.Commit(true)
panicError(err)
root, set := tree.Commit(true)

err = nodes.Merge(set)
err := nodes.Merge(set)
panicError(err)

err = db.TrieDB().UpdateForOK(nodes, mpt.AccountStateRootRetriever.RetrieveStateRoot)
err = db.TrieDB().UpdateForOK(root, ethcmn.Hash{}, nodes, mpt.AccountStateRootRetriever.RetrieveStateRoot)
panicError(err)
err = db.TrieDB().Commit(root, false, nil)
err = db.TrieDB().Commit(root, false)
panicError(err)

setMptRootHash(db, uint64(height), root, isEvm)
Expand Down
8 changes: 4 additions & 4 deletions cmd/okbchaind/mpt/iavl2mpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package mpt
import (
"bytes"
"fmt"
"github.com/ethereum/go-ethereum/trie"
"log"

ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
apptypes "github.com/okx/okbchain/app/types"
"github.com/okx/okbchain/libs/cosmos-sdk/server"
"github.com/okx/okbchain/libs/cosmos-sdk/store/mpt"
Expand Down Expand Up @@ -56,7 +56,7 @@ func migrateAccFromIavlToMpt(ctx *server.Context) {

// 1.1 update GlobalNumber to mpt
accountNumber := migrationApp.AccountKeeper.GetNextAccountNumber(cmCtx)
err = accTrie.TryUpdate(authtypes.GlobalAccountNumberKey, migrationApp.Codec().MustMarshalBinaryLengthPrefixed(accountNumber))
err = accTrie.UpdateStorage(ethcmn.Address{}, authtypes.GlobalAccountNumberKey, migrationApp.Codec().MustMarshalBinaryLengthPrefixed(accountNumber))
panicError(err)
fmt.Println("GlobalNumber", accountNumber)
//TODO need re-build migrateAccFromIavlToMpt cmd
Expand All @@ -71,7 +71,7 @@ func migrateAccFromIavlToMpt(ctx *server.Context) {
}

// update acc mpt for every account
panicError(accTrie.TryUpdate(key, value))
panicError(accTrie.UpdateStorage(ethcmn.Address{}, key, value))
if count%100 == 0 {
pushData2Database(accMptDb, accTrie, committedHeight, false, nodes)
log.Println(count)
Expand All @@ -82,7 +82,7 @@ func migrateAccFromIavlToMpt(ctx *server.Context) {
if !bytes.Equal(ethAcc.CodeHash, mpt.EmptyCodeHashBytes) {
contractCount++
// update evm mpt. Key is the address of the contract; Value is the empty root hash
panicError(evmTrie.TryUpdate(ethAcc.EthAddress().Bytes(), ethtypes.EmptyRootHash.Bytes()))
panicError(evmTrie.UpdateStorage(ethcmn.Address{}, ethAcc.EthAddress().Bytes(), ethtypes.EmptyRootHash.Bytes()))
if contractCount%100 == 0 {
pushData2Database(evmMptDb, evmTrie, committedHeight, true, nodes)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/okbchaind/repair_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/okx/okbchain/app/utils/appstatus"
"github.com/okx/okbchain/libs/cosmos-sdk/server"
"github.com/okx/okbchain/libs/cosmos-sdk/store/flatkv"
"github.com/okx/okbchain/libs/cosmos-sdk/store/mpt"
sdk "github.com/okx/okbchain/libs/cosmos-sdk/types"
tmiavl "github.com/okx/okbchain/libs/iavl"
"github.com/okx/okbchain/libs/system/trace"
Expand Down Expand Up @@ -49,6 +50,7 @@ func repairStateCmd(ctx *server.Context) *cobra.Command {
cmd.Flags().StringP(pprofAddrFlag, "p", "0.0.0.0:6060", "Address and port of pprof HTTP server listening")
cmd.Flags().Bool(tmiavl.FlagIavlDiscardFastStorage, false, "Discard fast storage")
cmd.Flags().MarkHidden(tmiavl.FlagIavlDiscardFastStorage)
cmd.Flags().Bool(mpt.FlagTriePbss, false, "Enable pbss")

return cmd
}
Expand All @@ -63,4 +65,5 @@ func setExternalPackageValue() {
tmiavl.SetEnableFastStorage(true)
tmiavl.SetIgnoreAutoUpgrade(true)
}
mpt.TriePbss = viper.GetBool(mpt.FlagTriePbss)
}
77 changes: 43 additions & 34 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ require (
github.com/cosmos/ledger-cosmos-go v0.11.1
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b
github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25
github.com/ethereum/go-ethereum v1.10.8
github.com/ethereum/go-ethereum v1.10.26
github.com/fortytw2/leaktest v1.3.0
github.com/fsnotify/fsnotify v1.6.0
github.com/go-errors/errors v1.0.1
github.com/go-errors/errors v1.4.2
github.com/go-kit/kit v0.12.0
github.com/go-logfmt/logfmt v0.5.1
github.com/go-redis/redis/v8 v8.11.4
github.com/goccy/go-json v0.9.7
github.com/go-redis/redis/v8 v8.11.5
github.com/goccy/go-json v0.9.11
github.com/gogo/gateway v1.1.0
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/google/btree v1.0.0
github.com/google/btree v1.0.1
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa
github.com/google/gops v0.3.23
github.com/google/orderedcode v0.0.1
Expand All @@ -50,7 +50,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/libp2p/go-buffer-pool v0.1.0
github.com/magiconair/properties v1.8.6
github.com/mattn/go-isatty v0.0.14
github.com/mattn/go-isatty v0.0.16
github.com/miguelmota/go-ethereum-hdwallet v0.0.0-20210614093730-56a4d342a6ff
github.com/minio/highwayhash v1.0.2
github.com/mitchellh/go-homedir v1.1.0
Expand All @@ -60,7 +60,7 @@ require (
github.com/pelletier/go-toml v1.9.5
github.com/pkg/errors v0.9.1
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/client_golang v1.14.0
github.com/rakyll/statik v0.1.6
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
github.com/regen-network/cosmos-proto v0.3.1
Expand All @@ -71,30 +71,30 @@ require (
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.12.0
github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48
github.com/status-im/keycard-go v0.2.0
github.com/stretchr/testify v1.8.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/btcd v0.1.1
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15
github.com/tendermint/go-amino v0.16.0
github.com/tendermint/tm-db v0.6.7
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef
github.com/tyler-smith/go-bip39 v1.1.0
github.com/valyala/fastjson v1.6.3
go.etcd.io/bbolt v1.3.6
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
golang.org/x/crypto v0.1.0
golang.org/x/net v0.8.0
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
gorm.io/driver/mysql v1.3.3
gorm.io/gorm v1.23.3
sigs.k8s.io/yaml v1.2.0
)

require (
github.com/DataDog/zstd v1.4.1 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 // indirect
Expand All @@ -104,54 +104,62 @@ require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/cosmos/ledger-go v0.9.2 // indirect
github.com/danieljoos/wincred v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/dgraph-io/badger/v2 v2.2007.2 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de // indirect
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.0 // indirect
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f // indirect
github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand All @@ -164,11 +172,12 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand All @@ -177,7 +186,7 @@ replace (
github.com/buger/jsonparser => github.com/buger/jsonparser v1.0.0 // imported by nacos-go-sdk, upgraded to v1.0.0 in case of a known vulnerable bug
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/gorocksdb => github.com/okx/grocksdb v1.6.45-okc2
github.com/ethereum/go-ethereum => github.com/okx/go-ethereum v1.10.26-0.20230605041300-9db59c1d91e6
github.com/ethereum/go-ethereum => github.com/okx/go-ethereum v1.10.9-0.20230615142245-7be68cd3f535
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4
github.com/tendermint/go-amino => github.com/okx/go-amino v0.15.1-okc4
Expand Down
Loading