feat!: Comet v0.38 Integration (#15519)

Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>
Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Aleksandr Bezobchuk
2023-05-24 16:09:19 +00:00
committed by GitHub
co-authored by marbar3778 cool-developer Aaron Craelius Matt Kocubinski Julien Robert
parent 166be3766b
commit 6cee22df52
148 changed files with 14747 additions and 15262 deletions
+20 -27
View File
@@ -9,7 +9,6 @@ import (
"syscall"
"cosmossdk.io/log"
abcitypes "github.com/cometbft/cometbft/abci/types"
cmtcfg "github.com/cometbft/cometbft/config"
cmted25519 "github.com/cometbft/cometbft/crypto/ed25519"
"github.com/cometbft/cometbft/node"
@@ -17,7 +16,10 @@ import (
"github.com/cometbft/cometbft/privval"
"github.com/cometbft/cometbft/proxy"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/server"
servercmtlog "github.com/cosmos/cosmos-sdk/server/log"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)
@@ -27,21 +29,15 @@ import (
// As CometStart is more broadly used in the codebase,
// the number of available methods on CometStarter will grow.
type CometStarter struct {
logger log.Logger
app abcitypes.Application
cfg *cmtcfg.Config
valPrivKey cmted25519.PrivKey
genesis []byte
rootDir string
rpcListen bool
logger log.Logger
app servertypes.ABCI
cfg *cmtcfg.Config
valPrivKey cmted25519.PrivKey
genesis []byte
rootDir string
rpcListen bool
tcpAddrChooser func() string
startTries int
startTries int
}
// NewCometStarter accepts a minimal set of arguments to start comet with an ABCI app.
@@ -49,7 +45,7 @@ type CometStarter struct {
//
// NewCometStarter(...).Logger(...).Start()
func NewCometStarter(
app abcitypes.Application,
app servertypes.ABCI,
cfg *cmtcfg.Config,
valPrivKey cmted25519.PrivKey,
genesis []byte,
@@ -92,16 +88,12 @@ func NewCometStarter(
// and bumping it up to 12 makes it almost never fail.
const defaultStartTries = 12
return &CometStarter{
logger: log.NewNopLogger(),
app: app,
logger: log.NewNopLogger(),
app: app,
cfg: cfg,
genesis: genesis,
valPrivKey: valPrivKey,
rootDir: rootDir,
rootDir: rootDir,
startTries: defaultStartTries,
}
}
@@ -132,8 +124,8 @@ func (s *CometStarter) Start() (n *node.Node, err error) {
return nil, err
}
// Wrap this defer in an anonymous function so we don't immediately evaluate n,
// which would always be nil at thi spoint.
// Wrap this defer in an anonymous function so we don't immediately evaluate
// n, which would always be nil at this point.
defer func() {
globalCometMu.Release(n)
}()
@@ -153,6 +145,7 @@ func (s *CometStarter) Start() (n *node.Node, err error) {
return appGenesis.ToGenesisDoc()
}
cmtApp := server.NewCometABCIWrapper(s.app)
for i := 0; i < s.startTries; i++ {
s.cfg.P2P.ListenAddress = s.likelyAvailableAddress()
if s.rpcListen {
@@ -163,9 +156,9 @@ func (s *CometStarter) Start() (n *node.Node, err error) {
s.cfg,
fpv,
nodeKey,
proxy.NewLocalClientCreator(s.app),
proxy.NewLocalClientCreator(cmtApp),
appGenesisProvider,
node.DefaultDBProvider,
cmtcfg.DefaultDBProvider,
node.DefaultMetricsProvider(s.cfg.Instrumentation),
servercmtlog.CometLoggerWrapper{Logger: s.logger},
)
+3 -3
View File
@@ -44,9 +44,9 @@ func NewNetwork(nVals int, createCometStarter func(int) *CometStarter) (Nodes, e
return
}
// Notify that the new node's switch is available,
// so this node can be peered with the other nodes.
switchCh <- n.PEXReactor().Switch
// Notify that the new node's switch is available, so this node can be
// peered with the other nodes.
switchCh <- n.Switch()
// And assign the node into its correct index in the ordered slice.
nodes[i] = n
+15 -4
View File
@@ -12,15 +12,26 @@ import (
// If totalWait has elapsed and the desired height has not been reached,
// an error is returned.
func WaitForNodeHeight(n *node.Node, desiredHeight int64, totalWait time.Duration) error {
const backoff = 100 * time.Millisecond
attempts := int64(totalWait / backoff)
const backOff = 100 * time.Millisecond
attempts := int64(totalWait / backOff)
// In Comet 0.37, the consensus state was exposed directly on the Node.
// As of 0.38, the node no longer exposes consensus state,
// but the consensus state is available as a field on the RPC environment.
//
// Luckily, in 0.38 the RPC environment is no longer a package-level singleton,
// so retrieving the RPC environment for a single node should be safe.
env, err := n.ConfigureRPC()
if err != nil {
return fmt.Errorf("failed to configure RPC to reach into consensus state: %w", err)
}
curHeight := int64(-1)
for i := int64(0); i < attempts; i++ {
curHeight = n.ConsensusState().GetLastHeight()
curHeight = env.ConsensusState.GetState().LastBlockHeight
if curHeight < desiredHeight {
time.Sleep(backoff)
time.Sleep(backOff)
continue
}