Skip to content

Commit

Permalink
oracle: remove block height consensus (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobhjkim authored Aug 16, 2024
1 parent d428470 commit 426c647
Show file tree
Hide file tree
Showing 29 changed files with 279 additions and 1,951 deletions.
12 changes: 8 additions & 4 deletions proto/settlus/oracle/v1alpha1/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ message Params {
uint64 max_miss_count_per_slash_window = 5;
}

enum OralceTopic {
// OracleTopic defines the type of oracle data. It is used to distinguish
// different types of oracle data.
enum OracleTopic {
// DEPRECATED: Do not use.
BLOCK = 0;
// Ownership defines nft ownership consensus.
OWNERSHIP = 1;
}

message OracleData {
OralceTopic topic = 1;
OracleTopic topic = 1;
repeated string sources = 2;
}

message VoteData {
OralceTopic topic = 1;
OracleTopic topic = 1;
repeated string data = 2;
}

Expand Down Expand Up @@ -70,4 +74,4 @@ message RoundInfo {
repeated OracleData oracle_data = 4;
// UNIX time in milliseconds
int64 timestamp = 5;
}
}
28 changes: 0 additions & 28 deletions proto/settlus/oracle/v1alpha1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ service Query {
option (google.api.http).get = "/settlus/oracle/v1alpha1/params";
}

// Queries a list of BlockData items for a given chainId.
rpc BlockData(QueryBlockDataRequest) returns (QueryBlockDataResponse) {
option (google.api.http).get =
"/settlus/oracle/v1alpha1/block_data/{chain_id}";
}

// Queries a list of BlockDatas items for all chainIds.
rpc AllBlockData(QueryAllBlockDataRequest)
returns (QueryAllBlockDataResponse) {
option (google.api.http).get = "/settlus/oracle/v1alpha1/block_data";
}

// Queries an aggregate prevote of a validator.
rpc AggregatePrevote(QueryAggregatePrevoteRequest)
returns (QueryAggregatePrevoteResponse) {
Expand Down Expand Up @@ -93,22 +81,6 @@ message QueryParamsResponse {
Params params = 1 [ (gogoproto.nullable) = false ];
}

// QueryBlockDataRequest is request type for the Query/BlockData RPC method.
message QueryBlockDataRequest { string chain_id = 1; }

// QueryBlockDataResponse is response type for the Query/BlockData RPC method.
message QueryBlockDataResponse { BlockData block_data = 1; }

// QueryAllBlockDataRequest is request type for the Query/AllBlockData RPC
// method.
message QueryAllBlockDataRequest {}

// QueryAllBlockDataResponse is response type for the Query/AllBlockData RPC
// method.
message QueryAllBlockDataResponse {
repeated BlockData block_data = 2 [ (gogoproto.nullable) = false ];
}

// QueryFeederDelegationRequest is request type for the Query/FeederDelegation
// RPC method.
message QueryFeederDelegationRequest { string validator_address = 1; }
Expand Down
2 changes: 1 addition & 1 deletion swagger/swagger-ui/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -19724,7 +19724,7 @@
}
}
},
"settlus.oracle.v1alpha1.OralceTopic": {
"settlus.oracle.v1alpha1.OracleTopic": {
"type": "string",
"enum": [
"BLOCK",
Expand Down
47 changes: 8 additions & 39 deletions tools/interop-node/feeder/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,18 @@ func (feeder *Feeder) HandlePrevote(ctx context.Context) error {
voteData := types.VoteDataArr{}
for _, od := range round.OracleData {
switch od.Topic {
case oracletypes.OralceTopic_BLOCK:
blockDataStr, err := feeder.gatherBlockDataString(od.Sources, uint64(round.Timestamp))
if err != nil {
feeder.abstainRoundId = round.Id
return err
}

voteData = append(voteData, &oracletypes.VoteData{
Topic: oracletypes.OralceTopic_BLOCK,
Data: blockDataStr,
})

case oracletypes.OralceTopic_OWNERSHIP:
case oracletypes.OracleTopic_OWNERSHIP:
nftDataStr, err := feeder.gatherNftOwnerDataString(od.Sources, uint64(round.Timestamp))
if err != nil {
feeder.abstainRoundId = round.Id
return err
}
voteData = append(voteData, &oracletypes.VoteData{
Topic: oracletypes.OralceTopic_OWNERSHIP,
Topic: oracletypes.OracleTopic_OWNERSHIP,
Data: nftDataStr,
})
default:
feeder.logger.Debug("unsupported oracle topic", "topic", od.Topic)
}
}

Expand Down Expand Up @@ -175,7 +165,7 @@ func (feeder *Feeder) HandleAbstain(ctx context.Context) error {
}

// abstain from voting
abstainData := []*oracletypes.VoteData{}
var abstainData []*oracletypes.VoteData
if err := feeder.sendPrevote(ctx, abstainData, salt, round.Id); err != nil {
return fmt.Errorf("failed to send abstain prevote: %w", err)
}
Expand All @@ -189,20 +179,6 @@ func (feeder *Feeder) HandleAbstain(ctx context.Context) error {
return nil
}

func (feeder *Feeder) gatherBlockDataString(chainIds []string, timestamp uint64) ([]string, error) {
blockDataList := make([]oracletypes.BlockData, len(chainIds))
for idx, cid := range chainIds {
bd, err := feeder.getOldestBlock(cid, timestamp)
if err != nil {
return nil, err
}

blockDataList[idx] = bd
}

return blockDataListToBlockDataString(blockDataList), nil
}

func (feeder *Feeder) getOldestBlock(chainId string, timestamp uint64) (oracletypes.BlockData, error) {
sub, ok := feeder.subscribers[chainId]
if !ok {
Expand All @@ -217,6 +193,7 @@ func (feeder *Feeder) getOldestBlock(chainId string, timestamp uint64) (oraclety
}, err
}

// gatherNftOwnerDataString gathers nft owner data string from the subscribers
func (feeder *Feeder) gatherNftOwnerDataString(nftIds []string, timestamp uint64) ([]string, error) {
s := make([]string, len(nftIds))
for i, nftId := range nftIds {
Expand All @@ -237,6 +214,7 @@ func (feeder *Feeder) gatherNftOwnerDataString(nftIds []string, timestamp uint64

owner, err := sub.OwnerOf(context.TODO(), nft.ContractAddr.String(), nft.TokenId.String(), bd.BlockHash)
if err != nil {
feeder.logger.Debug("failed to get ownerOf", "nftId", nftId, "error", err)
return nil, err
}

Expand All @@ -250,7 +228,7 @@ func (feeder *Feeder) gatherNftOwnerDataString(nftIds []string, timestamp uint64
func (feeder *Feeder) sendVote(ctx context.Context) error {
if feeder.lastPreVote.Salt == "" {
// we skip if salt is empty, which means no previous prevote was sent.
feeder.logger.Info("salt or blockDataString is empty, skipping this vote period...")
feeder.logger.Info("salt or datastring is empty, skipping this vote period...")
return nil
}

Expand Down Expand Up @@ -290,12 +268,3 @@ func (feeder *Feeder) sendPrevote(ctx context.Context, vda types.VoteDataArr, sa

return nil
}

// BlockDataListToBlockDataString converts a list of BlockData to a string
func blockDataListToBlockDataString(bdList []oracletypes.BlockData) []string {
s := make([]string, len(bdList))
for i, bd := range bdList {
s[i] = fmt.Sprintf("%s:%d/%s", bd.ChainId, bd.BlockNumber, bd.BlockHash)
}
return s
}
43 changes: 0 additions & 43 deletions tools/interop-node/feeder/feeder_test.go
Original file line number Diff line number Diff line change
@@ -1,44 +1 @@
package feeder

import (
"testing"

oracletypes "github.com/settlus/chain/x/oracle/types"
"github.com/stretchr/testify/require"
)

func Test_BlockDataListToBlockDataString(t *testing.T) {
type args struct {
bdList []oracletypes.BlockData
}
tests := []struct {
name string
args args
want []string
}{
{
name: "test",
args: args{
bdList: []oracletypes.BlockData{
{
ChainId: "1",
BlockNumber: 123,
BlockHash: "0x123",
},
{
ChainId: "2",
BlockNumber: 456,
BlockHash: "0x456",
},
},
},
want: []string{"1:123/0x123", "2:456/0x456"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := blockDataListToBlockDataString(tt.args.bdList)
require.EqualValues(t, tt.want, got)
})
}
}
20 changes: 10 additions & 10 deletions tools/interop-node/feeder/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func Test_GenerateSalt(t *testing.T) {

func Test_GeneratePrevoteHash(t *testing.T) {
type args struct {
blockDataString []string
salt string
dataString []string
salt string
}
tests := []struct {
name string
Expand All @@ -35,26 +35,26 @@ func Test_GeneratePrevoteHash(t *testing.T) {
{
name: "single chain",
args: args{
blockDataString: []string{"1:123:0x123"},
salt: "foo",
dataString: []string{"1/0x123/0x1:0xfoo"},
salt: "foo",
},
want: "01A164031A468DE61267F23A6BD7642AA33422C983D0E298085AEE1244A51F40",
want: "A13CCB8173F8C6919BAE51EAED94FA1066BCAF513F5C5286DBA8808A73C63449",
}, {
name: "multiple chains",
args: args{
blockDataString: []string{"1:123:0x123", "2:456:0x456"},
salt: "bar",
dataString: []string{"1/0x123/0x1:0xfoo", "2/0x456/0x2:0xbar"},
salt: "bar",
},
want: "1776F5F1BCACEFC9E75DA6623C9C9B1AA6DDF9831DBDEC3453D0C69B380FBE97",
want: "5669721A5163DA85815FB766730AC8755D2AC5AF053373EC3CB67135C3BCE21C",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
voteData := types.VoteDataArr{
{
Topic: oracletypes.OralceTopic_BLOCK,
Data: tt.args.blockDataString,
Topic: oracletypes.OracleTopic_OWNERSHIP,
Data: tt.args.dataString,
},
}
if got := feeder.GeneratePrevoteHash(voteData, tt.args.salt); got != tt.want {
Expand Down
20 changes: 0 additions & 20 deletions tools/interop-node/types/event.go

This file was deleted.

4 changes: 2 additions & 2 deletions tools/interop-node/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// At build time, the variables Name, Version, Commit, and BuildTags
// can be passed as build flags as shown in the following example:
//
// go build -X github.com/settlus/chain/tools/interop-node/version.Name=gaia \
// -X github.com/settlus/chain/tools/interop-node/version.AppName=gaiad \
// go build -X github.com/settlus/chain/tools/interop-node/version.Name=settlus \
// -X github.com/settlus/chain/tools/interop-node/version.AppName=settlusd \
// -X github.com/settlus/chain/tools/interop-node/version.Version=1.0 \
// -X github.com/settlus/chain/tools/interop-node/version.Commit=f0f7b7dab7e36c20b757cebce0e8f4fc5b95de60 \
// -X "github.com/settlus/chain/tools/interop-node/version.BuildTags=linux darwin amd64"
Expand Down
66 changes: 1 addition & 65 deletions x/oracle/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdQueryBlockData())
cmd.AddCommand(CmdQueryAllBlockData())
cmd.AddCommand(CmdQueryAggregatePrevote())
cmd.AddCommand(CmdQueryAggregatePrevotes())
cmd.AddCommand(CmdQueryAggregateVote())
Expand Down Expand Up @@ -64,68 +62,6 @@ func CmdQueryParams() *cobra.Command {
return cmd
}

// CmdQueryBlockData queries a list of BlockData items for a given chain ID.
func CmdQueryBlockData() *cobra.Command {
cmd := &cobra.Command{
Use: "block-data [chain-id]",
Short: "Query block data",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqChainId := args[0]

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryBlockDataRequest{

ChainId: reqChainId,
}

res, err := queryClient.BlockData(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// CmdQueryAllBlockData queries a list of all BlockData for all chain IDs.
func CmdQueryAllBlockData() *cobra.Command {
cmd := &cobra.Command{
Use: "all-block-data",
Short: "Query all block data",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryAllBlockDataRequest{}

res, err := queryClient.AllBlockData(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// CmdQueryAggregatePrevote queries an aggregate prevote of a validator.
func CmdQueryAggregatePrevote() *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -353,7 +289,7 @@ func CmdQueryRewardPool() *cobra.Command {
return cmd
}

// CmdQueryRewardPool queries the current oracle reward pool balance.
// CmdQueryCurrentRoundInfo queries the current oracle reward pool balance.
func CmdQueryCurrentRoundInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "round-info",
Expand Down
Loading

0 comments on commit 426c647

Please sign in to comment.