Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
Victor Neznaykin committed Aug 20, 2023
2 parents c25955a + 63cfcde commit 6d2aa35
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 151 deletions.
2 changes: 1 addition & 1 deletion delivery/broker/validator_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (b *Broker) PublishValidatorStatus(ctx context.Context, status model.ValidatorStatus) error {
if !checkCache(status.ValidatorAddress, status.Height, b.cache.valStatus) {
if !checkCache(status.ConsensusAddress, status.Height, b.cache.valStatus) {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (a *App) Start(ctx context.Context) error {
}
tallyCache.SetCompareFn(lessInt64)

modules := modules.BuildModules(b, a.log, grpcCli, *tb, cdc, a.cfg.Modules, parser, a.cfg.ParseAvatarURL, tallyCache)
modules := modules.BuildModules(b, a.log, grpcCli, *tb, cdc, a.cfg.Modules, parser, tallyCache)
ts := ts.NewToStorage()
w := worker.New(a.cfg.WorkerConfig, *a.log, b, rpcCli, grpcCli, modules, s, cdc, *tb, *ts)
server := server.New(a.cfg.Server, s, *a.log)
Expand Down
23 changes: 11 additions & 12 deletions internal/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ import (
)

type Config struct {
ChainPrefix string `env:"CHAIN_PREFIX"`
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
Server server.Config
Modules []string `env:"MODULES" required:"true"`
GRPCConfig grpc.Config
RPCConfig rpc.Config
BrokerConfig broker.Config
StorageConfig storage.Config
WorkerConfig worker.Config
StartTimeout time.Duration `env:"START_TIMEOUT"`
StopTimeout time.Duration `env:"STOP_TIMEOUT"`
ParseAvatarURL bool `env:"PARSE_AVATAR_URL" envDefault:"false"`
ChainPrefix string `env:"CHAIN_PREFIX"`
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
Server server.Config
Modules []string `env:"MODULES" required:"true"`
GRPCConfig grpc.Config
RPCConfig rpc.Config
BrokerConfig broker.Config
StorageConfig storage.Config
WorkerConfig worker.Config
StartTimeout time.Duration `env:"START_TIMEOUT"`
StopTimeout time.Duration `env:"STOP_TIMEOUT"`
}
42 changes: 21 additions & 21 deletions modules/distribution/begin_blocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func (m *Module) parseProposerRewardEvent(ctx context.Context, eventsMap types.B
}

var (
coin model.Coin
validator string
err error
coin model.Coin
operatorAddress string
err error
)

for _, event := range events {
Expand All @@ -72,7 +72,7 @@ func (m *Module) parseProposerRewardEvent(ctx context.Context, eventsMap types.B
continue
}

validator, coin, err = m.parseAttributes(event)
operatorAddress, coin, err = m.parseAttributes(event)
if err != nil {
m.log.Error().
Err(err).
Expand All @@ -83,9 +83,9 @@ func (m *Module) parseProposerRewardEvent(ctx context.Context, eventsMap types.B
}

if err = m.broker.PublishProposerReward(ctx, model.ProposerReward{
Height: height,
Validator: validator,
Reward: coin,
Height: height,
OperatorAddress: operatorAddress,
Reward: coin,
}); err != nil {
m.log.Error().
Err(err).
Expand All @@ -107,9 +107,9 @@ func (m *Module) parseCommissionEvent(ctx context.Context, eventsMap types.Block
}

var (
validator string
coin model.Coin
err error
operatorAddress string
coin model.Coin
err error
)

for _, event := range events {
Expand All @@ -121,7 +121,7 @@ func (m *Module) parseCommissionEvent(ctx context.Context, eventsMap types.Block
continue
}

validator, coin, err = m.parseAttributes(event)
operatorAddress, coin, err = m.parseAttributes(event)
if err != nil {
m.log.Error().
Err(err).
Expand All @@ -132,9 +132,9 @@ func (m *Module) parseCommissionEvent(ctx context.Context, eventsMap types.Block
}

if err = m.broker.PublishDistributionCommission(ctx, model.DistributionCommission{
Height: height,
Validator: validator,
Amount: coin,
Height: height,
OperatorAddress: operatorAddress,
Amount: coin,
}); err != nil {
m.log.Error().
Err(err).
Expand All @@ -156,9 +156,9 @@ func (m *Module) parseRewardsEvent(ctx context.Context, eventsMap types.BlockerE
}

var (
validator string
coin model.Coin
err error
operatorAddress string
coin model.Coin
err error
)

for _, event := range events {
Expand All @@ -170,7 +170,7 @@ func (m *Module) parseRewardsEvent(ctx context.Context, eventsMap types.BlockerE
continue
}

validator, coin, err = m.parseAttributes(event)
operatorAddress, coin, err = m.parseAttributes(event)
if err != nil {
m.log.Error().
Err(err).
Expand All @@ -181,9 +181,9 @@ func (m *Module) parseRewardsEvent(ctx context.Context, eventsMap types.BlockerE
}

if err = m.broker.PublishDistributionReward(ctx, model.DistributionReward{
Height: height,
Validator: validator,
Amount: coin,
Height: height,
OperatorAddress: operatorAddress,
Amount: coin,
}); err != nil {
m.log.Error().
Err(err).
Expand Down
4 changes: 2 additions & 2 deletions modules/distribution/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (m *Module) HandleMessage(ctx context.Context, index int, cosmosMsg sdk.Msg
Coins: m.tbM.MapCoins(coin),
Height: tx.Height,
DelegatorAddress: msg.DelegatorAddress,
ValidatorAddress: msg.ValidatorAddress,
OperatorAddress: msg.ValidatorAddress,
TxHash: tx.TxHash,
MsgIndex: int64(index),
})
Expand Down Expand Up @@ -86,7 +86,7 @@ func (m *Module) HandleMessage(ctx context.Context, index int, cosmosMsg sdk.Msg
TxHash: tx.TxHash,
MsgIndex: int64(index),
WithdrawCommission: m.tbM.MapCoins(coins),
ValidatorAddress: msg.ValidatorAddress,
OperatorAddress: msg.ValidatorAddress,
})
}

Expand Down
4 changes: 2 additions & 2 deletions modules/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func BuildModules(b rep.Broker, log *zerolog.Logger, cli *grpcClient.Client, tbMapper tb.ToBroker,
cdc codec.Codec, modules []string, addressesParser coreModule.MessageAddressesParser, parseAvatarURL bool,
cdc codec.Codec, modules []string, addressesParser coreModule.MessageAddressesParser,
tallyCache govModule.TallyCache[uint64, int64]) []types.Module {

res := make([]types.Module, 0)
Expand All @@ -49,7 +49,7 @@ func BuildModules(b rep.Broker, log *zerolog.Logger, cli *grpcClient.Client, tbM
res = append(res, mintModule.New(b, cli, tbMapper))
case "staking":
log.Info().Msg("staking module registered")
res = append(res, stakingModule.New(b, cli, tbMapper, cdc, modules, parseAvatarURL))
res = append(res, stakingModule.New(b, cli, tbMapper, cdc, modules))
case "distribution":
log.Info().Msg("distribution module registered")
res = append(res, distributionModule.New(b, cli, tbMapper, cdc))
Expand Down
16 changes: 8 additions & 8 deletions modules/slashing/begin_blocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (m *Module) handleSlashEvent(ctx context.Context, eventsMap types.BlockerEv
return nil
}

var address, power, reason, jailed string
var operatorAddress, power, reason, jailed string
for _, e := range events {
if len(e.Attributes) < 4 {
m.log.Warn().
Expand All @@ -62,7 +62,7 @@ func (m *Module) handleSlashEvent(ctx context.Context, eventsMap types.BlockerEv

switch attr.Key {
case slashingtypes.AttributeKeyAddress, base64KeyAddress: // required
address = attr.Value
operatorAddress = attr.Value
case slashingtypes.AttributeKeyPower, base64KeyPower: // required
power = attr.Value
case slashingtypes.AttributeKeyReason, base64KeyReason: // required
Expand Down Expand Up @@ -111,12 +111,12 @@ func (m *Module) handleSlashEvent(ctx context.Context, eventsMap types.BlockerEv
}

if err := m.broker.PublishHandleValidatorSignature(ctx, model.HandleValidatorSignature{
Address: address,
Power: power,
Reason: reason,
Jailed: jailed,
Burned: burned,
Height: height,
OperatorAddress: operatorAddress,
Power: power,
Reason: reason,
Jailed: jailed,
Burned: burned,
Height: height,
}); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions modules/slashing/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func (m *Module) HandleMessage(ctx context.Context, index int, cosmosMsg sdk.Msg

func (m *Module) handleMsgUnjail(ctx context.Context, tx *types.Tx, index int, msg *slashtypes.MsgUnjail) error {
return m.broker.PublishUnjailMessage(ctx, model.UnjailMessage{
Height: tx.Height,
Hash: tx.TxHash,
Index: int64(index),
ValidatorAddr: msg.ValidatorAddr,
Height: tx.Height,
Hash: tx.TxHash,
Index: int64(index),
OperatorAddress: msg.ValidatorAddr,
})
}
12 changes: 6 additions & 6 deletions modules/staking/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (m *Module) HandleGenesis(
}

// Publish the description
if err := m.publishValidatorDescriptions(ctx, genState.Validators, doc.InitialHeight, m.parseAvatarURL); err != nil {
if err := m.publishValidatorDescriptions(ctx, genState.Validators, doc.InitialHeight); err != nil {
return fmt.Errorf("error while storing staking genesis validator descriptions: %w", err)
}

Expand Down Expand Up @@ -206,11 +206,11 @@ func (m *Module) publishUnbondingDelegations(ctx context.Context, doc *cometbftt
coin = types.NewCoinFromCdk(sdk.NewCoin(genState.Params.BondDenom, entry.InitialBalance))
// TODO: test it
if err := m.broker.PublishUnbondingDelegation(ctx, model.UnbondingDelegation{
Height: doc.InitialHeight,
DelegatorAddress: ud.DelegatorAddress,
ValidatorAddress: validator.OperatorAddress,
Coin: m.tbM.MapCoin(coin),
CompletionTimestamp: entry.CompletionTime,
Height: doc.InitialHeight,
DelegatorAddress: ud.DelegatorAddress,
OperatorAddress: validator.OperatorAddress,
Coin: m.tbM.MapCoin(coin),
CompletionTime: entry.CompletionTime,
}); err != nil {
return err
}
Expand Down
32 changes: 10 additions & 22 deletions modules/staking/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,13 @@ func (m *Module) handleMsgCreateValidator(
return err
}

var avatarURL string
if m.parseAvatarURL {
avatarURL = m.getAvatarURL(msg.ValidatorAddress, msg.Description.Identity, height)
}

if err = m.broker.PublishValidatorDescription(ctx, model.ValidatorDescription{
OperatorAddress: msg.ValidatorAddress,
Moniker: msg.Description.Moniker,
Identity: msg.Description.Identity,
Website: msg.Description.Website,
SecurityContact: msg.Description.SecurityContact,
Details: msg.Description.Details,
AvatarURL: avatarURL,
Height: height,
}); err != nil {
return err
Expand Down Expand Up @@ -217,23 +211,23 @@ func (m *Module) handleMsgUndelegate(ctx context.Context, tx *types.Tx, index in
}
// TODO: test it
if err = m.broker.PublishUnbondingDelegation(ctx, model.UnbondingDelegation{
Height: tx.Height,
DelegatorAddress: msg.DelegatorAddress,
ValidatorAddress: msg.ValidatorAddress,
Coin: m.tbM.MapCoin(types.NewCoinFromCdk(msg.Amount)),
CompletionTimestamp: completionTime,
Height: tx.Height,
DelegatorAddress: msg.DelegatorAddress,
OperatorAddress: msg.ValidatorAddress,
Coin: m.tbM.MapCoin(types.NewCoinFromCdk(msg.Amount)),
CompletionTime: completionTime,
}); err != nil {
return err
}

// TODO: test it
if err = m.broker.PublishUnbondingDelegationMessage(ctx, model.UnbondingDelegationMessage{
UnbondingDelegation: model.UnbondingDelegation{
Height: tx.Height,
DelegatorAddress: msg.DelegatorAddress,
ValidatorAddress: msg.ValidatorAddress,
Coin: m.tbM.MapCoin(types.NewCoinFromCdk(msg.Amount)),
CompletionTimestamp: completionTime,
Height: tx.Height,
DelegatorAddress: msg.DelegatorAddress,
OperatorAddress: msg.ValidatorAddress,
Coin: m.tbM.MapCoin(types.NewCoinFromCdk(msg.Amount)),
CompletionTime: completionTime,
},
TxHash: tx.TxHash,
MsgIndex: int64(index),
Expand Down Expand Up @@ -320,19 +314,13 @@ func (m *Module) handleEditValidator(
return err
}

var avatarURL string
if m.parseAvatarURL {
avatarURL = m.getAvatarURL(msg.ValidatorAddress, msg.Description.Identity, height)
}

if err := m.broker.PublishValidatorDescription(ctx, model.ValidatorDescription{
OperatorAddress: msg.ValidatorAddress,
Moniker: msg.Description.Moniker,
Identity: msg.Description.Identity,
Website: msg.Description.Website,
SecurityContact: msg.Description.SecurityContact,
Details: msg.Description.Details,
AvatarURL: avatarURL,
Height: height,
}); err != nil {
return err
Expand Down
7 changes: 1 addition & 6 deletions modules/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package staking

import (
"os"
"sync"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -31,13 +30,11 @@ type (
broker broker
tbM tb.ToBroker
cdc codec.Codec
avatarURLCache sync.Map
enabledModules []string // xxx fixme
parseAvatarURL bool
}
)

func New(b broker, cli *grpcClient.Client, tbM tb.ToBroker, cdc codec.Codec, modules []string, parseAvatarURL bool) *Module {
func New(b broker, cli *grpcClient.Client, tbM tb.ToBroker, cdc codec.Codec, modules []string) *Module {
l := zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().
Str("module", moduleName).Logger()

Expand All @@ -48,8 +45,6 @@ func New(b broker, cli *grpcClient.Client, tbM tb.ToBroker, cdc codec.Codec, mod
tbM: tbM,
cdc: cdc,
enabledModules: modules,
avatarURLCache: sync.Map{},
parseAvatarURL: parseAvatarURL,
}
}

Expand Down
Loading

0 comments on commit 6d2aa35

Please sign in to comment.