Skip to content

Commit

Permalink
Merge pull request #204 from tellor-io/add-events
Browse files Browse the repository at this point in the history
added events to certain operations
  • Loading branch information
themandalore authored Jul 15, 2024
2 parents 4d3f8d8 + 7673e62 commit 1de8595
Show file tree
Hide file tree
Showing 22 changed files with 1,563 additions and 214 deletions.
1,020 changes: 887 additions & 133 deletions api/layer/reporter/query.pulsar.go

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions proto/layer/reporter/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,21 @@ message QueryParamsResponse {
}

// QueryReportersRequest is the request type for the Query/Reporters RPC method.
message QueryReportersRequest {}
message QueryReportersRequest {
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}
message reporter {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
OracleReporter metadata = 2;
}

// QueryReportersResponse is the response type for the Query/Reporters RPC method.
message QueryReportersResponse {
// all the reporters.
repeated OracleReporter reporters = 1;
repeated reporter reporters = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QuerySelectorReporterRequest is the request type for the
Expand Down
35 changes: 18 additions & 17 deletions x/bridge/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
gomath "math"
"math/big"
"sort"
"strconv"
"time"

"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down Expand Up @@ -249,34 +250,34 @@ func (k Keeper) SetBridgeValidatorParams(ctx context.Context, bridgeValidatorSet
k.Logger(ctx).Info("Error getting latest checkpoint index: ", "error", err)
return err
}
var valsetSigs *types.BridgeValsetSignatures
if valsetIdx.Index == 0 {
valsetSigs := types.NewBridgeValsetSignatures(len(bridgeValidatorSet.BridgeValidatorSet))
err = k.BridgeValsetSignaturesMap.Set(ctx, validatorTimestamp, *valsetSigs)
valsetSigs = types.NewBridgeValsetSignatures(len(bridgeValidatorSet.BridgeValidatorSet))
} else {
previousValsetTimestamp, err := k.ValidatorCheckpointIdxMap.Get(ctx, valsetIdx.Index-1)
if err != nil {
k.Logger(ctx).Info("Error getting previous valset timestamp: ", "error", err)
return err
}
previousValset, err := k.BridgeValsetByTimestampMap.Get(ctx, previousValsetTimestamp.Timestamp)
if err != nil {
k.Logger(ctx).Info("Error setting bridge valset signatures: ", "error", err)
k.Logger(ctx).Info("Error getting previous valset: ", "error", err)
return err
}

return nil
}
previousValsetTimestamp, err := k.ValidatorCheckpointIdxMap.Get(ctx, valsetIdx.Index-1)
if err != nil {
k.Logger(ctx).Info("Error getting previous valset timestamp: ", "error", err)
return err
valsetSigs = types.NewBridgeValsetSignatures(len(previousValset.BridgeValidatorSet))
}
previousValset, err := k.BridgeValsetByTimestampMap.Get(ctx, previousValsetTimestamp.Timestamp)
if err != nil {
k.Logger(ctx).Info("Error getting previous valset: ", "error", err)
return err
}

valsetSigs := types.NewBridgeValsetSignatures(len(previousValset.BridgeValidatorSet))
err = k.BridgeValsetSignaturesMap.Set(ctx, validatorTimestamp, *valsetSigs)
if err != nil {
k.Logger(ctx).Info("Error setting bridge valset signatures: ", "error", err)
return err
}

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"new_bridge_validator_set",
sdk.NewAttribute("timestamp", strconv.FormatUint(validatorTimestamp, 10)),
),
})
return nil
}

Expand Down
9 changes: 9 additions & 0 deletions x/bridge/keeper/msg_server_claim_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"strconv"

"github.com/tellor-io/layer/x/bridge/types"

Expand All @@ -14,5 +15,13 @@ func (k msgServer) ClaimDeposit(goCtx context.Context, msg *types.MsgClaimDeposi
if err := k.Keeper.ClaimDeposit(sdkCtx, msg.DepositId, msg.Index); err != nil {
return nil, err
}

sdk.UnwrapSDKContext(goCtx).EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"deposit_claimed",
sdk.NewAttribute("deposit_id", strconv.FormatUint(msg.DepositId, 10)),
),
})

return &types.MsgClaimDepositResponse{}, nil
}
7 changes: 7 additions & 0 deletions x/bridge/keeper/msg_server_request_attestations.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,12 @@ func (k msgServer) RequestAttestations(ctx context.Context, msg *types.MsgReques
return nil, status.Error(codes.Internal, err.Error())
}

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"attestations_request",
sdk.NewAttribute("query_id", msg.QueryId),
sdk.NewAttribute("timestamp", msg.Timestamp),
),
})
return &types.MsgRequestAttestationsResponse{}, nil
}
8 changes: 8 additions & 0 deletions x/bridge/keeper/msg_server_withdraw_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ func (k msgServer) WithdrawTokens(goCtx context.Context, msg *types.MsgWithdrawT
if err := k.Keeper.WithdrawTokens(sdkCtx, msg.Amount, sender, recipient); err != nil {
return nil, err
}
sdk.UnwrapSDKContext(goCtx).EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"tokens_withdrawn",
sdk.NewAttribute("sender", msg.Creator),
sdk.NewAttribute("recipient_evm_address", msg.Recipient),
sdk.NewAttribute("amount", msg.Amount.String()),
),
})
return &types.MsgWithdrawTokensResponse{}, nil
}
27 changes: 26 additions & 1 deletion x/dispute/keeper/dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package keeper
import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
gomath "math"
"math/big"
"strconv"

layertypes "github.com/tellor-io/layer/types"
"github.com/tellor-io/layer/x/dispute/types"
Expand Down Expand Up @@ -123,6 +125,22 @@ func (k Keeper) SetNewDispute(ctx sdk.Context, sender sdk.AccAddress, msg types.
if err != nil {
return err
}
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"new_dispute",
sdk.NewAttribute("disputer", msg.Creator),
sdk.NewAttribute("reporter", msg.Report.Reporter),
sdk.NewAttribute("dispute_category", msg.DisputeCategory.String()),
sdk.NewAttribute("total_fee", disputeFee.String()),
sdk.NewAttribute("fee_paid", msg.Fee.Amount.String()),
sdk.NewAttribute("pay_from_bond", strconv.FormatBool(msg.PayFromBond)),
sdk.NewAttribute("dispute_id", strconv.FormatUint(disputeId, 10)),
sdk.NewAttribute("value", msg.Report.Value),
sdk.NewAttribute("query_type", msg.Report.QueryType),
sdk.NewAttribute("query_id", hex.EncodeToString(msg.Report.QueryId)),
sdk.NewAttribute("report_block_number", strconv.FormatInt(msg.Report.BlockNumber, 10)),
),
})
return k.Disputes.Set(ctx, dispute.DisputeId, dispute)
}

Expand Down Expand Up @@ -226,6 +244,7 @@ func (k Keeper) AddDisputeRound(ctx sdk.Context, sender sdk.AccAddress, dispute
if err := k.CloseDispute(ctx, dispute.DisputeId); err != nil {
return err
}
prevDisputeId := dispute.DisputeId
dispute.BurnAmount = dispute.BurnAmount.Add(roundFee)
dispute.FeeTotal = dispute.FeeTotal.Add(msg.Fee.Amount)
disputeId := k.NextDisputeId(ctx)
Expand All @@ -242,7 +261,13 @@ func (k Keeper) AddDisputeRound(ctx sdk.Context, sender sdk.AccAddress, dispute
if err != nil {
return err
}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"added_dispute_round",
sdk.NewAttribute("prev_dispute_id", strconv.FormatUint(prevDisputeId, 10)),
sdk.NewAttribute("dispute_id", strconv.FormatUint(disputeId, 10)),
),
})
return k.SetStartVote(ctx, dispute.DisputeId) // starting voting immediately
}

Expand Down
8 changes: 8 additions & 0 deletions x/dispute/keeper/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"errors"
"strconv"

layer "github.com/tellor-io/layer/types"
"github.com/tellor-io/layer/x/dispute/types"
Expand Down Expand Up @@ -141,6 +142,13 @@ func (k Keeper) ExecuteVote(ctx context.Context, id uint64) error {
case types.VoteResult_NO_TALLY:
return errors.New("vote hasn't been tallied yet")
}
sdk.UnwrapSDKContext(ctx).EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"dispute_executed",
sdk.NewAttribute("dispute_id", strconv.FormatUint(id, 10)),
sdk.NewAttribute("vote_result", vote.VoteResult.String()),
),
})
return k.BlockInfo.Remove(ctx, dispute.HashId)
}

Expand Down
11 changes: 10 additions & 1 deletion x/dispute/keeper/msg_server_add_fee_to_dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"errors"
"strconv"

layer "github.com/tellor-io/layer/types"
"github.com/tellor-io/layer/x/dispute/types"
Expand Down Expand Up @@ -82,6 +83,14 @@ func (k msgServer) AddFeeToDispute(goCtx context.Context,
if err := k.Keeper.Disputes.Set(ctx, dispute.DisputeId, dispute); err != nil {
return nil, err
}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"fee_added_to_dispute",
sdk.NewAttribute("payer", msg.Creator),
sdk.NewAttribute("dispute_id", strconv.FormatUint(dispute.DisputeId, 10)),
sdk.NewAttribute("amount", msg.Amount.Amount.String()),
sdk.NewAttribute("paid_from_bond", strconv.FormatBool(msg.PayFromBond)),
),
})
return &types.MsgAddFeeToDisputeResponse{}, nil
}
10 changes: 10 additions & 0 deletions x/dispute/keeper/msg_server_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"errors"
"strconv"

"github.com/tellor-io/layer/x/dispute/types"

Expand Down Expand Up @@ -80,5 +81,14 @@ func (k msgServer) Vote(goCtx context.Context, msg *types.MsgVote) (*types.MsgVo
if err := k.Voter.Set(ctx, collections.Join(vote.Id, voterAcc.Bytes()), voterVote); err != nil {
return nil, err
}
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"voted_on_dispute",
sdk.NewAttribute("voter", msg.Voter),
sdk.NewAttribute("voter_power", voterPower.String()),
sdk.NewAttribute("dispute_id", strconv.FormatUint(msg.Id, 10)),
sdk.NewAttribute("choice", msg.Vote.String()),
),
})
return &types.MsgVoteResponse{}, nil
}
7 changes: 7 additions & 0 deletions x/mint/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/tellor-io/layer/x/mint/types"

"cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type msgServer struct {
Expand Down Expand Up @@ -33,5 +35,10 @@ func (k msgServer) Init(goCtx context.Context, msg *types.MsgInit) (*types.MsgMs
if err := k.Minter.Set(goCtx, minter); err != nil {
return nil, err
}
sdk.UnwrapSDKContext(goCtx).EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"minter_initialized",
),
})
return &types.MsgMsgInitResponse{}, nil
}
10 changes: 10 additions & 0 deletions x/oracle/keeper/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ func (k Keeper) SetAggregate(ctx context.Context, report *types.Aggregate) error
currentTimestamp := sdkCtx.BlockTime().UnixMilli()
report.Height = sdkCtx.BlockHeight()

sdk.UnwrapSDKContext(ctx).EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"aggregate_report",
sdk.NewAttribute("query_id", hex.EncodeToString(report.QueryId)),
sdk.NewAttribute("value", report.AggregateValue),
sdk.NewAttribute("standard_deviation", fmt.Sprintf("%f", report.StandardDeviation)),
sdk.NewAttribute("number_of_reporters", fmt.Sprintf("%d", len(report.Reporters))),
sdk.NewAttribute("micro_report_height", fmt.Sprintf("%d", report.MicroHeight)),
),
})
return k.Aggregates.Set(ctx, collections.Join(report.QueryId, currentTimestamp), *report)
}

Expand Down
10 changes: 9 additions & 1 deletion x/oracle/keeper/msg_server_tip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"encoding/hex"
"errors"
"fmt"

Expand Down Expand Up @@ -90,6 +91,13 @@ func (k msgServer) Tip(goCtx context.Context, msg *types.MsgTip) (*types.MsgTipR
if err != nil {
return nil, err
}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"tip_added",
sdk.NewAttribute("query_id", hex.EncodeToString(queryId)),
sdk.NewAttribute("tipper", tipper.String()),
sdk.NewAttribute("amount", tip.Amount.String()),
),
})
return &types.MsgTipResponse{}, nil
}
15 changes: 14 additions & 1 deletion x/oracle/keeper/msg_update_cyclelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package keeper

import (
"context"
"encoding/hex"
"fmt"

"github.com/tellor-io/layer/x/oracle/types"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k msgServer) UpdateCyclelist(ctx context.Context, req *types.MsgUpdateCyclelist) (*types.MsgUpdateCyclelistResponse, error) {
Expand All @@ -19,6 +23,15 @@ func (k msgServer) UpdateCyclelist(ctx context.Context, req *types.MsgUpdateCycl
if err := k.keeper.InitCycleListQuery(ctx, req.Cyclelist); err != nil {
return nil, err
}

queries := make([]string, len(req.Cyclelist))
for i, query := range req.Cyclelist {
queries[i] = hex.EncodeToString(query)
}
sdk.UnwrapSDKContext(ctx).EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"cyclelist_updated",
sdk.NewAttribute("cyclelist", fmt.Sprintf("%v", queries)),
),
})
return &types.MsgUpdateCyclelistResponse{}, nil
}
14 changes: 13 additions & 1 deletion x/oracle/keeper/submit_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"encoding/hex"
"fmt"

"github.com/tellor-io/layer/utils"
Expand Down Expand Up @@ -51,7 +52,18 @@ func (k Keeper) setValue(ctx context.Context, reporter sdk.AccAddress, query typ
if err != nil {
return err
}

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"new_report",
sdk.NewAttribute("reporter", reporter.String()),
sdk.NewAttribute("reporter_power", fmt.Sprintf("%d", power)),
sdk.NewAttribute("query_type", queryType),
sdk.NewAttribute("query_id", hex.EncodeToString(queryId)),
sdk.NewAttribute("value", val),
sdk.NewAttribute("cyclelist", fmt.Sprintf("%t", incycle)),
sdk.NewAttribute("aggregate_method", dataSpec.AggregationMethod),
),
})
return k.Reports.Set(ctx, collections.Join3(queryId, reporter.Bytes(), query.Id), report)
}

Expand Down
11 changes: 11 additions & 0 deletions x/registry/keeper/msg_server_register_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,16 @@ func (k msgServer) RegisterSpec(goCtx context.Context, msg *types.MsgRegisterSpe
return nil, err
}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"register_data_spec",
sdk.NewAttribute("registrar", msg.Registrar),
sdk.NewAttribute("document_hash_id", msg.Spec.DocumentHash),
sdk.NewAttribute("query_type", msg.QueryType),
sdk.NewAttribute("aggregate_method", msg.Spec.AggregationMethod),
sdk.NewAttribute("response_value_type", msg.Spec.ResponseValueType),
sdk.NewAttribute("report_buffer_window", msg.Spec.ReportBufferWindow.String()),
),
})
return &types.MsgRegisterSpecResponse{}, nil
}
Loading

0 comments on commit 1de8595

Please sign in to comment.