Skip to content

Commit

Permalink
Merge branch 'release/v1.7.0' into yls/fix-EstimateGas-170
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangjianmeng authored Jul 15, 2024
2 parents c9470f5 + 75b80fe commit 08f1c4f
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ type OecConfig struct {
maxSubscriptionClients int

maxTxLimitPerPeer uint64

enableP2PIPWhitelist bool
consensusIPWhitelist map[string]bool
}

const (
Expand Down Expand Up @@ -153,6 +156,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 @@ -260,6 +265,7 @@ func defaultOecConfig() *OecConfig {
mempoolForceRecheckGap: 2000,
commitGapHeight: iavlconfig.DefaultCommitGapHeight,
iavlFSCacheSize: tmiavl.DefaultIavlFastStorageCacheSize,
consensusIPWhitelist: map[string]bool{},
}
}

Expand Down Expand Up @@ -316,6 +322,9 @@ func (c *OecConfig) loadFromConfig() {
c.SetGcInterval(viper.GetInt(FlagDebugGcInterval))
c.SetIavlAcNoBatch(viper.GetBool(tmiavl.FlagIavlCommitAsyncNoBatch))
c.SetMaxSubscriptionClients(viper.GetInt(FlagMaxSubscriptionClients))

c.SetEnableP2PIPWhitelist(viper.GetBool(FlagEnableP2PIPWhitelist))
c.SetConsensusIPWhitelist(viper.GetString(FlagConsensusIPWhitelist))
}

func resolveNodeKeyWhitelist(plain string) []string {
Expand Down Expand Up @@ -680,6 +689,14 @@ func (c *OecConfig) updateFromKVStr(k, v string) {
return
}
c.SetMaxSubscriptionClients(r)
case FlagEnableP2PIPWhitelist:
r, err := strconv.ParseBool(v)
if err != nil {
return
}
c.SetEnableP2PIPWhitelist(r)
case FlagConsensusIPWhitelist:
c.SetConsensusIPWhitelist(v)
}

}
Expand Down Expand Up @@ -1119,3 +1136,23 @@ func (c *OecConfig) SetMaxTxLimitPerPeer(maxTxLimitPerPeer int64) {
func (c *OecConfig) GetMaxTxLimitPerPeer() uint64 {
return c.maxTxLimitPerPeer
}

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

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

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
}
}
8 changes: 8 additions & 0 deletions libs/tendermint/blockchain/v0/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v0
import (
"errors"
"fmt"
cfg "github.com/okex/exchain/libs/tendermint/config"
"reflect"
"sync"
"time"
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 @@ -35,6 +35,8 @@ type IDynamicConfig interface {
GetDynamicGpMaxGasUsed() int64
GetMaxSubscriptionClients() int
GetMaxTxLimitPerPeer() uint64
GetEnableP2PIPWhitelist() bool
GetConsensusIPWhitelist() map[string]bool
}

var DynamicConfig IDynamicConfig = MockDynamicConfig{}
Expand Down Expand Up @@ -203,3 +205,9 @@ func (d *MockDynamicConfig) SetMaxSubscriptionClients(value int) {
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{}
}
9 changes: 9 additions & 0 deletions libs/tendermint/consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package consensus
import (
"bytes"
"fmt"
cfg "github.com/okex/exchain/libs/tendermint/config"
"github.com/okex/exchain/libs/tendermint/crypto"
"github.com/okex/exchain/libs/tendermint/libs/automation"
"reflect"
Expand Down Expand Up @@ -343,6 +344,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 @@ -2,6 +2,7 @@ package evidence

import (
"fmt"
cfg "github.com/okex/exchain/libs/tendermint/config"
"reflect"
"time"

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 08f1c4f

Please sign in to comment.