Skip to content

Commit

Permalink
Merge branch 'dev' into yls/change-pubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
ylsGit authored Jul 17, 2024
2 parents ac86622 + e690f11 commit 271e050
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ IGNORE_CHECK_GO=false
install_rocksdb_version:=$(ROCKSDB_VERSION)


Version=v1.8.0
Version=v1.8.1
CosmosSDK=v0.39.2
Tendermint=v0.33.9
Iavl=v0.14.3
Expand Down
36 changes: 36 additions & 0 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ type OecConfig struct {
maxSubscriptionClients int

maxTxLimitPerPeer uint64

enableP2PIPWhitelist bool
consensusIPWhitelist map[string]bool
}

const (
Expand Down Expand Up @@ -168,6 +171,8 @@ const (
FlagDynamicGpMaxTxNum = "dynamic-gp-max-tx-num"
FlagEnableWrappedTx = "enable-wtx"
FlagSentryAddrs = "p2p.sentry_addrs"
FlagEnableP2PIPWhitelist = "p2p.enable_ip_whitelist"
FlagConsensusIPWhitelist = "p2p.consensus_ip_whitelist"
FlagCsTimeoutPropose = "consensus.timeout_propose"
FlagCsTimeoutProposeDelta = "consensus.timeout_propose_delta"
FlagCsTimeoutPrevote = "consensus.timeout_prevote"
Expand Down Expand Up @@ -280,6 +285,7 @@ func defaultOecConfig() *OecConfig {
mempoolForceRecheckGap: 2000,
commitGapHeight: iavlconfig.DefaultCommitGapHeight,
iavlFSCacheSize: tmiavl.DefaultIavlFastStorageCacheSize,
consensusIPWhitelist: map[string]bool{},
}
}

Expand Down Expand Up @@ -331,6 +337,8 @@ func (c *OecConfig) loadFromConfig() {
c.SetCommitGapHeight(viper.GetInt64(server.FlagCommitGapHeight))
c.SetSentryAddrs(viper.GetString(FlagSentryAddrs))
c.SetNodeKeyWhitelist(viper.GetString(FlagNodeKeyWhitelist))
c.SetEnableP2PIPWhitelist(viper.GetBool(FlagEnableP2PIPWhitelist))
c.SetConsensusIPWhitelist(viper.GetString(FlagConsensusIPWhitelist))
c.SetEnableWtx(viper.GetBool(FlagEnableWrappedTx))
c.SetEnableAnalyzer(viper.GetBool(trace.FlagEnableAnalyzer))
c.SetDeliverTxsExecuteMode(viper.GetInt(state.FlagDeliverTxsExecMode))
Expand Down Expand Up @@ -511,6 +519,14 @@ func (c *OecConfig) updateFromKVStr(k, v string) {
c.SetPendingPoolBlacklist(v)
case FlagNodeKeyWhitelist:
c.SetNodeKeyWhitelist(v)
case FlagEnableP2PIPWhitelist:
r, err := strconv.ParseBool(v)
if err != nil {
return
}
c.SetEnableP2PIPWhitelist(r)
case FlagConsensusIPWhitelist:
c.SetConsensusIPWhitelist(v)
case FlagMempoolCheckTxCost:
r, err := strconv.ParseBool(v)
if err != nil {
Expand Down Expand Up @@ -810,6 +826,14 @@ func (c *OecConfig) GetNodeKeyWhitelist() []string {
return c.nodeKeyWhitelist
}

func (c *OecConfig) GetEnableP2PIPWhitelist() bool {
return c.enableP2PIPWhitelist
}

func (c *OecConfig) GetConsensusIPWhitelist() map[string]bool {
return c.consensusIPWhitelist
}

func (c *OecConfig) GetMempoolCheckTxCost() bool {
return c.mempoolCheckTxCost
}
Expand All @@ -831,6 +855,18 @@ func (c *OecConfig) SetNodeKeyWhitelist(value string) {
}
}

func (c *OecConfig) SetEnableP2PIPWhitelist(value bool) {
c.enableP2PIPWhitelist = value
}

func (c *OecConfig) SetConsensusIPWhitelist(value string) {
c.consensusIPWhitelist = map[string]bool{}
ipList := resolveNodeKeyWhitelist(value)
for _, ip := range ipList {
c.consensusIPWhitelist[strings.TrimSpace(ip)] = true
}
}

func (c *OecConfig) GetSentryAddrs() []string {
return c.sentryAddrs
}
Expand Down
4 changes: 2 additions & 2 deletions app/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ func (api *PublicEthereumAPI) simDoCall(args rpctypes.CallArgs, cap uint64) (uin
}

// EstimateGas returns an estimate of gas usage for the given smart contract call.
func (api *PublicEthereumAPI) EstimateGas(args rpctypes.CallArgs, blockNrOrHash rpctypes.BlockNumberOrHash) (hexutil.Uint64, error) {
func (api *PublicEthereumAPI) EstimateGas(args rpctypes.CallArgs, blockNrOrHash *rpctypes.BlockNumberOrHash) (hexutil.Uint64, error) {
monitor := monitor.GetMonitor("eth_estimateGas", api.logger, api.Metrics).OnBegin()
defer monitor.OnEnd("args", args)
rateLimiter := api.GetRateLimiter("eth_estimateGas")
Expand Down Expand Up @@ -1715,7 +1715,7 @@ func (api *PublicEthereumAPI) generateFromArgs(args rpctypes.SendTxArgs) (*evmty
Value: args.Value,
Data: &input,
}
gl, err := api.EstimateGas(callArgs, rpctypes.BlockNumberOrHash{})
gl, err := api.EstimateGas(callArgs, nil)
if err != nil {
return nil, err
}
Expand Down
8 changes: 8 additions & 0 deletions libs/tendermint/blockchain/v0/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

amino "github.com/tendermint/go-amino"

cfg "github.com/okex/exchain/libs/tendermint/config"
"github.com/okex/exchain/libs/tendermint/libs/log"
"github.com/okex/exchain/libs/tendermint/p2p"
sm "github.com/okex/exchain/libs/tendermint/state"
Expand Down Expand Up @@ -221,6 +222,13 @@ func (bcR *BlockchainReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
case *bcBlockRequestMessage:
bcR.respondToPeer(msg, src)
case *bcBlockResponseMessage:
if cfg.DynamicConfig.GetEnableP2PIPWhitelist() {
okIP := cfg.DynamicConfig.GetConsensusIPWhitelist()[src.RemoteIP().String()]
if !okIP {
bcR.Logger.Error("consensus msg:IP not in whitelist", "IP", src.RemoteIP().String())
return
}
}
bcR.Logger.Info("AddBlock.", "Height", msg.Block.Height, "Peer", src.ID())
bcR.pool.AddBlock(src.ID(), msg, len(msgBytes))
case *bcStatusRequestMessage:
Expand Down
8 changes: 8 additions & 0 deletions libs/tendermint/config/dynamic_config_okchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type IDynamicConfig interface {
GetMaxSubscriptionClients() int
GetPendingPoolBlacklist() string
GetMaxTxLimitPerPeer() uint64
GetEnableP2PIPWhitelist() bool
GetConsensusIPWhitelist() map[string]bool
}

var DynamicConfig IDynamicConfig = MockDynamicConfig{}
Expand Down Expand Up @@ -233,3 +235,9 @@ func (d MockDynamicConfig) GetPendingPoolBlacklist() string {
func (c MockDynamicConfig) GetMaxTxLimitPerPeer() uint64 {
return DefaultMempoolConfig().MaxTxLimitPerPeer
}

func (c MockDynamicConfig) GetEnableP2PIPWhitelist() bool { return false }

func (c MockDynamicConfig) GetConsensusIPWhitelist() map[string]bool {
return map[string]bool{}
}
14 changes: 11 additions & 3 deletions libs/tendermint/consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package consensus
import (
"bytes"
"fmt"
"github.com/okex/exchain/libs/tendermint/crypto"
"github.com/okex/exchain/libs/tendermint/libs/automation"
"reflect"
"sync"
"time"

"github.com/pkg/errors"

amino "github.com/tendermint/go-amino"

cfg "github.com/okex/exchain/libs/tendermint/config"
cstypes "github.com/okex/exchain/libs/tendermint/consensus/types"
"github.com/okex/exchain/libs/tendermint/crypto"
"github.com/okex/exchain/libs/tendermint/libs/automation"
"github.com/okex/exchain/libs/tendermint/libs/bits"
tmevents "github.com/okex/exchain/libs/tendermint/libs/events"
"github.com/okex/exchain/libs/tendermint/libs/log"
Expand Down Expand Up @@ -343,6 +343,14 @@ func (conR *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
return
}

if cfg.DynamicConfig.GetEnableP2PIPWhitelist() {
okIP := cfg.DynamicConfig.GetConsensusIPWhitelist()[src.RemoteIP().String()]
if !okIP {
conR.Logger.Error("consensus msg:IP not in whitelist", "IP", src.RemoteIP().String())
return
}
}

msg, err := decodeMsg(msgBytes)
if err != nil {
conR.Logger.Error("Error decoding message", "src", src, "chId", chID, "msg", msg, "err", err, "bytes", msgBytes)
Expand Down
9 changes: 9 additions & 0 deletions libs/tendermint/evidence/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

amino "github.com/tendermint/go-amino"

cfg "github.com/okex/exchain/libs/tendermint/config"
clist "github.com/okex/exchain/libs/tendermint/libs/clist"
"github.com/okex/exchain/libs/tendermint/libs/log"
"github.com/okex/exchain/libs/tendermint/p2p"
Expand Down Expand Up @@ -63,6 +64,14 @@ func (evR *Reactor) AddPeer(peer p2p.Peer) {
// Receive implements Reactor.
// It adds any received evidence to the evpool.
func (evR *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
if cfg.DynamicConfig.GetEnableP2PIPWhitelist() {
okIP := cfg.DynamicConfig.GetConsensusIPWhitelist()[src.RemoteIP().String()]
if !okIP {
evR.Logger.Error("consensus msg:IP not in whitelist", "IP", src.RemoteIP().String())
return
}
}

msg, err := decodeMsg(msgBytes)
if err != nil {
evR.Logger.Error("Error decoding message", "src", src, "chId", chID, "msg", msg, "err", err, "bytes", msgBytes)
Expand Down
2 changes: 2 additions & 0 deletions libs/tendermint/rpc/core/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
VotingPower: votingPower,
},
}
result.NodeInfo.ListenAddr = ""
result.NodeInfo.Other.RPCAddress = ""
// update Network to the ChainID in state
result.NodeInfo.Network = env.ConsensusState.GetState().ChainID

Expand Down

0 comments on commit 271e050

Please sign in to comment.