Skip to content

Commit

Permalink
fixed chain syncing problems with oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
scottburch committed Mar 7, 2021
1 parent f4bdc42 commit 647fcf6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
4 changes: 2 additions & 2 deletions docs/setup/deployaddl.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ Deploy Additional Nodes
of them. We just choose to point to the first one here, for the purposes of
the documentation.

6. Edit ".blzd/config/app.toml" to set the minimum-gas-prices to “10.0ubnt
6. Edit ".blzd/config/app.toml" to set the minimum-gas-prices to “0.002ubnt

# The minimum gas prices a validator is willing to accept for processing a
# transaction. A transaction's fees must meet the minimum of any denomination
# specified in this config (e.g. 0.25token1;0.0001token2).
minimum-gas-prices = "10.0ubnt"
minimum-gas-prices = "0.002ubnt"
Remember that *every* node should have *at least* this minimum. Feel free
to set it higher if you wish.
Expand Down
28 changes: 23 additions & 5 deletions x/oracle/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -147,9 +148,9 @@ func sendVoteMsgs(values []SourceAndValue, cdc *codec.Codec) string {
msg, _ := generateVoteMsg(cdc, value)
msgs = append(msgs, msg)
}
logger.Info("Sending oracle vote messages", "count", len(msgs))
logger.Info("Sending feeder vote messages", "count", len(msgs))
result, _ := BroadcastOracleMessages(msgs, cdc)
logger.Info("Oracle vote messages sent", "hash", result.Hash)
logger.Info("Feeder vote messages sent", "hash", result.Hash)
return hex.EncodeToString(result.Hash)
}

Expand All @@ -163,12 +164,29 @@ func generateVoteMsg(cdc *codec.Codec, source SourceAndValue) (types.MsgOracleVo
fmt.Sprintf("%.12f", source.value),
config.UserAddress,
source.source.Name,
keeper.GetCurrentBatchId(),
getCurrentBatchId(),
)
err = msg.ValidateBasic()
return msg, err
}

func getCurrentBatchId() string {
t := time.Date(
time.Now().Year(),
time.Now().Month(),
time.Now().Day(),
time.Now().Hour(),
time.Now().Minute(),
0,
0,
time.UTC,
).String()
t = strings.Replace(t, ":00 +0000 UTC", "", 1)
t = strings.Replace(t, " ", "-", -1)
return t
}


func generateVoteProofMsg(cdc *codec.Codec, source SourceAndValue) (types.MsgOracleVoteProof, error) {
config, err := readOracleConfig()
if err != nil {
Expand Down Expand Up @@ -219,7 +237,7 @@ func BroadcastOracleMessages(msgs []sdk.Msg, cdc *codec.Codec) (*coretypes.Resul
rpcCtx := rpctypes.Context{}
result, err := core.BroadcastTxCommit(&rpcCtx, signedMsg)
if err != nil {
logger.Info("Error transmitting oracle messages")
logger.Info("Error transmitting feeder messages")
}
return result, nil
}
Expand All @@ -242,7 +260,7 @@ func StartFeeder(oracleKeeper Keeper, accountKeeper auth.AccountKeeper, cdc *cod

func waitForCtx() {
for currCtx == nil {
logger.Info("Oracle waiting for context")
logger.Info("Feeder waiting for context")
time.Sleep(5 * time.Second)
}
}
Expand Down
4 changes: 1 addition & 3 deletions x/oracle/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func handleMsgOracleAddSource(ctx sdk.Context, k keeper.Keeper, msg types.MsgOra

func handleMsgOracleVote(ctx sdk.Context, k keeper.Keeper, msg types.MsgOracleVote) (*sdk.Result, error) {
voteGood := k.IsVoteValid(ctx, msg)
logger.Info("Vote received", "name", msg.SourceName, "good", voteGood)

validator, found := k.GetValidator(ctx, msg.Valcons)
var weight sdk.Dec
Expand All @@ -98,9 +99,6 @@ func handleMsgOracleVote(ctx sdk.Context, k keeper.Keeper, msg types.MsgOracleVo
k.UpdateSourceValue(ctx, vote)
k.StoreVote(ctx, vote)
}



return &sdk.Result{Events: ctx.EventManager().Events()}, nil
}

Expand Down
24 changes: 3 additions & 21 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ package keeper

import (
"fmt"
"github.com/bluzelle/curium/x/oracle/types"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/privval"
"strings"
"time"

"github.com/bluzelle/curium/x/oracle/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var valueUpdateListeners []types.ValueUpdateListener = make([]types.ValueUpdateListener, 0)
Expand Down Expand Up @@ -46,21 +43,6 @@ func NewKeeper(cdc *codec.Codec, sourceStoreKey sdk.StoreKey, configStoreKey sdk
return keeper
}

func GetCurrentBatchId() string {
t := time.Date(
time.Now().Year(),
time.Now().Month(),
time.Now().Day(),
time.Now().Hour(),
time.Now().Minute(),
0,
0,
time.UTC,
).String()
t = strings.Replace(t, ":00 +0000 UTC", "", 1)
t = strings.Replace(t, " ", "-", -1)
return t
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/keeper/keeper_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ func (k Keeper) GetVoteStore(ctx sdk.Context) sdk.KVStore {
return ctx.KVStore(k.voteStoreKey)
}

func CreateVoteKey(sourceName string, valcons string) string {
return fmt.Sprintf("%s>%s>%s", GetCurrentBatchId(), sourceName, valcons)
func CreateVoteKey(vote types.Vote) string {
return fmt.Sprintf("%s>%s>%s", vote.Batch, vote.SourceName, vote.Valcons)
}

func (k Keeper) StoreVote(ctx sdk.Context, vote types.Vote) string {
key := CreateVoteKey(vote.SourceName, vote.Valcons)
key := CreateVoteKey(vote)
store := k.GetVoteStore(ctx)
store.Set([]byte(key), k.cdc.MustMarshalBinaryBare(vote))
return key
Expand Down

0 comments on commit 647fcf6

Please sign in to comment.