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

Fix broadcasting tx from cli #138

Merged
merged 29 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a68cf82
fix: heimdalld logger to use log_level flag
kamuikatsurgi Feb 5, 2025
0c98c51
chore: nit
kamuikatsurgi Feb 5, 2025
9f297c5
Fix checkpoint broadcasting from cli
avalkov Feb 3, 2025
4252cec
Fix lint
avalkov Feb 6, 2025
c240284
chore: use helper.LogLevel instead of log_level
kamuikatsurgi Feb 6, 2025
c6998c2
Use memdb for tempApp in rootCmd
avalkov Feb 6, 2025
7352b2d
Fix autocli
avalkov Feb 6, 2025
b78703c
Add bor cli missing flag
avalkov Feb 7, 2025
795ec14
Add missing milestone query methods to the cli
avalkov Feb 7, 2025
ca7d174
Merge branch 'develop' of https://github.com/0xPolygon/heimdall-v2 in…
pratikspatil024 Feb 7, 2025
16197e8
chore: use `cosmos-sdk` logger instead of `cometbft` (#142)
kamuikatsurgi Feb 8, 2025
bf6368a
fix: use info as default for now
kamuikatsurgi Feb 8, 2025
b5ea45a
refactor NewRootCmd() to get the log_level value
kamuikatsurgi Feb 9, 2025
7593fd8
Final changes
kamuikatsurgi Feb 10, 2025
7ad78dc
gci lint
kamuikatsurgi Feb 10, 2025
eb68a5f
Merge develop
kamuikatsurgi Feb 10, 2025
980b905
Merge avalkov/verify-checkpoint
kamuikatsurgi Feb 10, 2025
d24ac16
Lint
kamuikatsurgi Feb 10, 2025
2ecfcac
Merge pull request #139 from 0xPolygon/krishang/fix-logs
avalkov Feb 10, 2025
fcf486a
Fix log
avalkov Feb 10, 2025
76557ad
tx: fixed the chain ID passed to the tx factory
pratikspatil024 Feb 10, 2025
799a04d
Merge pull request #143 from 0xPolygon/fix-chain-id
pratikspatil024 Feb 11, 2025
8744f49
Register MsgServer for chainmanager
avalkov Feb 11, 2025
ff82975
Merge develop
kamuikatsurgi Feb 12, 2025
fc42747
stake: bug fix in signer-update
pratikspatil024 Feb 12, 2025
efcda3b
update logging
pratikspatil024 Feb 12, 2025
6d732ad
removed duplicate function
pratikspatil024 Feb 12, 2025
d81dbb4
Merge pull request #145 from 0xPolygon/fix-stake-commands
pratikspatil024 Feb 12, 2025
97f9211
Take into account --chain arg
avalkov Feb 12, 2025
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 bridge/broadcaster/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"sync"
"time"

"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
Expand Down
2 changes: 1 addition & 1 deletion bridge/broadcaster/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestBroadcastToHeimdall(t *testing.T) {
t.Parallel()

viper.Set(helper.CometBFTNodeFlag, dummyCometBFTNodeUrl)
viper.Set("log_level", "info")
viper.Set(helper.LogLevel, "info")

srvconf := serverconfig.DefaultConfig()
configuration := helper.GetDefaultHeimdallConfig()
Expand Down
6 changes: 3 additions & 3 deletions bridge/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"time"

cometbftLogger "github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"
rpcserver "github.com/cometbft/cometbft/rpc/jsonrpc/server"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -53,13 +53,13 @@ var rootCmd = &cobra.Command{
}

// BridgeCommands returns command for bridge service
func BridgeCommands(v *viper.Viper, loggerInstance cometbftLogger.Logger, caller string) *cobra.Command {
func BridgeCommands(v *viper.Viper, loggerInstance log.Logger, caller string) *cobra.Command {
DecorateWithBridgeRootFlags(rootCmd, v, loggerInstance, caller)
return rootCmd
}

// DecorateWithBridgeRootFlags is called when bridge flags needs to be added to command
func DecorateWithBridgeRootFlags(cmd *cobra.Command, v *viper.Viper, loggerInstance cometbftLogger.Logger, caller string) {
func DecorateWithBridgeRootFlags(cmd *cobra.Command, v *viper.Viper, loggerInstance log.Logger, caller string) {
cmd.PersistentFlags().StringP(helper.CometBFTNodeFlag, "n", helper.DefaultCometBFTNode, "Node to connect to")

if err := v.BindPFlag(helper.CometBFTNodeFlag, cmd.PersistentFlags().Lookup(helper.CometBFTNodeFlag)); err != nil {
Expand Down
7 changes: 0 additions & 7 deletions bridge/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,6 @@ func GetStartCmd() *cobra.Command {
},
}

// log level
startCmd.Flags().String(helper.LogLevel, "info", "Log level for bridge")

if err := viper.BindPFlag(helper.LogLevel, startCmd.Flags().Lookup(helper.LogLevel)); err != nil {
logger.Error("GetStartCmd | BindPFlag | logLevel", "Error", err)
}

startCmd.Flags().Bool("all", false, "Start all bridge services")

if err := viper.BindPFlag("all", startCmd.Flags().Lookup("all")); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion bridge/listener/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"math/big"
"time"

"github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down
4 changes: 2 additions & 2 deletions bridge/listener/rootchain_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (rl *RootChainListener) handleStakedLog(vLog types.Log, selectedEvent *abi.
rl.Logger.Error("Error while parsing event", "name", selectedEvent.Name, "error", err)
}

if !util.IsPubKeyFirstByteValid(pubKey[0:1]) {
if !helper.IsPubKeyFirstByteValid(pubKey[0:1]) {
rl.Logger.Error("public key first byte mismatch", "expected", "0x04", "received", pubKey[0:1])
}

Expand Down Expand Up @@ -107,7 +107,7 @@ func (rl *RootChainListener) handleSignerChangeLog(vLog types.Log, selectedEvent
rl.Logger.Error("Error while parsing event", "name", selectedEvent.Name, "error", err)
}

if bytes.Equal(event.SignerPubkey, pubKey[1:]) && util.IsPubKeyFirstByteValid(pubKey[0:1]) {
if bytes.Equal(event.SignerPubkey, pubKey[1:]) && helper.IsPubKeyFirstByteValid(pubKey[0:1]) {
rl.SendTaskWithDelay("sendSignerChangeToHeimdall", selectedEvent.Name, logBytes, 0, event)
} else if isCurrentValidator, delay := util.CalculateTaskDelay(event, rl.cliCtx.Codec); isCurrentValidator {
rl.SendTaskWithDelay("sendSignerChangeToHeimdall", selectedEvent.Name, logBytes, delay, event)
Expand Down
6 changes: 4 additions & 2 deletions bridge/listener/service.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package listener

import (
"os"

logger "github.com/cometbft/cometbft/libs/log"
common "github.com/cometbft/cometbft/libs/service"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/codec"

"github.com/0xPolygon/heimdall-v2/bridge/queue"
"github.com/0xPolygon/heimdall-v2/bridge/util"
"github.com/0xPolygon/heimdall-v2/helper"
)

Expand All @@ -30,7 +32,7 @@ func NewListenerService(cdc codec.Codec, queueConnector *queue.QueueConnector, h
// creating listener object
listenerService := &ListenerService{}

listenerService.BaseService = *common.NewBaseService(util.Logger().With("service", "listener"), listenerServiceStr, listenerService)
listenerService.BaseService = *common.NewBaseService(logger.NewTMLogger(logger.NewSyncWriter(os.Stdout)).With("service", "listener"), listenerServiceStr, listenerService)

rootchainListener := NewRootChainListener()
rootchainListener.BaseListener = *NewBaseListener(cdc, queueConnector, httpClient, helper.GetMainClient(), rootChainListenerStr, rootchainListener)
Expand Down
2 changes: 1 addition & 1 deletion bridge/processor/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"time"

"github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down
2 changes: 1 addition & 1 deletion bridge/processor/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func (cp *CheckpointProcessor) createAndSendCheckpointToHeimdall(checkpointConte
"start", start,
"end", end,
"root", common.Bytes2Hex(root),
"accountRoot", accountRootHash,
"accountRoot", common.Bytes2Hex(accountRootHash),
)

chainParams := checkpointContext.ChainmanagerParams.ChainParams
Expand Down
5 changes: 2 additions & 3 deletions bridge/processor/clerk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func prepareClerkProcessor() (*ClerkProcessor, error) {
cdc := codec.NewProtoCodec(interfaceRegistry)

viper.Set(helper.CometBFTNodeFlag, dummyCometBFTNode)
viper.Set("log_level", "debug")
viper.Set(helper.LogLevel, "debug")
helper.InitTestHeimdallConfig("")

srvconf := serverconfig.DefaultConfig()
Expand Down Expand Up @@ -296,7 +296,7 @@ func prepareRootChainListener() (*listener.RootChainListener, func(), error) {
cdc := codec.NewProtoCodec(interfaceRegistry)

viper.Set(helper.CometBFTNodeFlag, dummyCometBFTNode)
viper.Set("log_level", "debug")
viper.Set(helper.LogLevel, "debug")

srvconf := serverconfig.DefaultConfig()
configuration := helper.GetDefaultHeimdallConfig()
Expand All @@ -312,7 +312,6 @@ func prepareRootChainListener() (*listener.RootChainListener, func(), error) {
stopFn := func() {}

rcl := listener.NewRootChainListener()
rcl.Logger = helper.Logger

server, err := getTestServer()
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions bridge/processor/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authTx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

"github.com/0xPolygon/heimdall-v2/bridge/util"
Expand Down Expand Up @@ -89,7 +90,7 @@ func (sp *StakingProcessor) sendValidatorJoinToHeimdall(eventName string, logByt
"nonce", event.Nonce,
"amount", event.Amount,
"totalAmount", event.Total,
"SignerPubkey", string(signerPubKey[:]),
"SignerPubkey", common.Bytes2Hex(signerPubKey),
"txHash", vLog.TxHash.String(),
"logIndex", uint64(vLog.Index),
"blockNumber", vLog.BlockNumber,
Expand All @@ -115,7 +116,7 @@ func (sp *StakingProcessor) sendValidatorJoinToHeimdall(eventName string, logByt
"nonce", event.Nonce,
"amount", event.Amount,
"totalAmount", event.Total,
"SignerPubkey", string(signerPubKey[:]),
"SignerPubkey", common.Bytes2Hex(signerPubKey),
"txHash", vLog.TxHash.String(),
"logIndex", uint64(vLog.Index),
"blockNumber", vLog.BlockNumber,
Expand Down Expand Up @@ -347,7 +348,7 @@ func (sp *StakingProcessor) sendSignerChangeToHeimdall(eventName string, logByte
newSignerPubKey = util.AppendPrefix(newSignerPubKey)
}

if !util.IsPubKeyFirstByteValid(newSignerPubKey) {
if !helper.IsPubKeyFirstByteValid(newSignerPubKey) {
sp.Logger.Error("Invalid signer pubkey", "event", eventName, "newSignerPubKey", newSignerPubKey)
return fmt.Errorf("invalid signer pubkey")
}
Expand All @@ -357,7 +358,7 @@ func (sp *StakingProcessor) sendSignerChangeToHeimdall(eventName string, logByte
"event", eventName,
"validatorID", event.ValidatorId,
"nonce", event.Nonce,
"NewSignerPubkey", string(newSignerPubKey[:]),
"NewSignerPubkey", common.Bytes2Hex(newSignerPubKey),
"oldSigner", event.OldSigner.Hex(),
"newSigner", event.NewSigner.Hex(),
"txHash", vLog.TxHash.String(),
Expand Down Expand Up @@ -386,7 +387,7 @@ func (sp *StakingProcessor) sendSignerChangeToHeimdall(eventName string, logByte
"event", eventName,
"validatorID", event.ValidatorId,
"nonce", event.Nonce,
"NewSignerPubkey", string(newSignerPubKey[:]),
"NewSignerPubkey", common.Bytes2Hex(newSignerPubKey),
"oldSigner", event.OldSigner.Hex(),
"newSigner", event.NewSigner.Hex(),
"txHash", vLog.TxHash.String(),
Expand Down
2 changes: 1 addition & 1 deletion bridge/queue/connector.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package queue

import (
"cosmossdk.io/log"
"github.com/RichardKnop/machinery/v1"
"github.com/RichardKnop/machinery/v1/config"
"github.com/cometbft/cometbft/libs/log"
"github.com/streadway/amqp"
)

Expand Down
37 changes: 2 additions & 35 deletions bridge/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ import (
"net/http"
"net/url"
"strconv"
"sync"
"time"

mLog "github.com/RichardKnop/machinery/v1/log"
"github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
addressCodec "github.com/cosmos/cosmos-sdk/codec/address"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/pkg/errors"
"github.com/spf13/viper"

"github.com/0xPolygon/heimdall-v2/contracts/statesender"
"github.com/0xPolygon/heimdall-v2/helper"
Expand Down Expand Up @@ -87,39 +84,9 @@ const (
BridgeDBFlag = "bridge-db"
)

var (
logger log.Logger
loggerOnce sync.Once
)

// Logger returns logger singleton instance
func Logger() log.Logger {
loggerOnce.Do(func() {
defaultLevel := "info"
logsWriter := helper.GetLogsWriter(helper.GetConfig().LogsWriterFile)
logger = log.NewTMLogger(log.NewSyncWriter(logsWriter))
option, err := log.AllowLevel(viper.GetString("log_level"))
if err != nil {
// cosmos sdk is using different style of log format
// and levels don't map well, config.toml
// see: https://github.com/cosmos/cosmos-sdk/pull/8072
logger.Error("Unable to parse logging level", "Error", err)
logger.Info("Using default log level")
option, err = log.AllowLevel(defaultLevel)
if err != nil {
logger.Error("failed to allow default log level", "Level", defaultLevel, "Error", err)
}
}

logger = log.NewFilter(logger, option)

// set no-op logger if log level is not debug for machinery
if viper.GetString("log_level") != "debug" {
mLog.SetDebug(NoopLogger{})
}
})

return logger
return helper.Logger.With("module", "bridge")
}

// IsProposer checks if we are proposer
Expand Down
5 changes: 5 additions & 0 deletions cmd/heimdalld/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func initAppConfig() (string, interface{}) {

customAppTemplate := serverconfig.DefaultConfigTemplate + helper.DefaultConfigTemplate

stringConfgValue := viper.GetViper().GetString(helper.ChainFlag)
if stringConfgValue != "" {
customAppConfig.Custom.Chain = stringConfgValue
}

return customAppTemplate, customAppConfig
}

Expand Down
6 changes: 2 additions & 4 deletions cmd/heimdalld/cmd/migration/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"strconv"

"cosmossdk.io/log"
"cosmossdk.io/math"
logger "github.com/cometbft/cometbft/libs/log"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"
dbm "github.com/cosmos/cosmos-db"
Expand All @@ -24,7 +22,7 @@ import (

// VerifyMigration verifies the migration from Heimdall v1 to Heimdall v2 by consuming the migrated genesis file
// and verifying balances, validators, bor spans, clerk events, and checkpoints
func VerifyMigration(hv1GenesisPath, hv2GenesisPath string, logger logger.Logger) error {
func VerifyMigration(hv1GenesisPath, hv2GenesisPath string, logger log.Logger) error {
logger.Info("Verifying migration")

hv1Genesis, err := utils.LoadJSONFromFile(hv1GenesisPath)
Expand All @@ -37,7 +35,7 @@ func VerifyMigration(hv1GenesisPath, hv2GenesisPath string, logger logger.Logger
appOptions := make(simtestutil.AppOptionsMap)
appOptions[flags.FlagHome] = heimdallApp.DefaultNodeHome

app := heimdallApp.NewHeimdallApp(log.NewLogger(os.Stderr), db, nil, true, appOptions)
app := heimdallApp.NewHeimdallApp(logger, db, nil, true, appOptions)

ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()})

Expand Down
4 changes: 2 additions & 2 deletions cmd/heimdalld/cmd/migration/verify/verify_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"os"
"time"

logger "github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"
)

const (
Expand All @@ -22,7 +22,7 @@ const (

// VerifyMigratedGenesisHash verifies the SHA256 hash of the migrated genesis file against a remote precomputed hash.
// It computes the hash of the local file, fetches the precomputed hash from the remote JSON file, then compares the two hashes.
func VerifyMigratedGenesisHash(migratedGenesisFilePath string, logger logger.Logger) error {
func VerifyMigratedGenesisHash(migratedGenesisFilePath string, logger log.Logger) error {
logger.Info("Generating migrated genesis hash...")

localHash, err := computeFileHash(migratedGenesisFilePath)
Expand Down
Loading
Loading