Skip to content

Commit

Permalink
add prepareOracleVotes impl
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-soon authored and yan-soon committed Apr 16, 2024
1 parent 5ddda97 commit 617f655
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func NewNodeWithContext(ctx context.Context,
}

// Make OracleReactor
oracleReactor := oracle.NewReactor(config.Oracle, pubKey, privValidator)
oracleReactor := oracle.NewReactor(config.Oracle, pubKey, privValidator, proxyApp.Consensus())
oracleInfo := oracleReactor.OracleInfo

// make block executor for consensus and blocksync reactors to execute blocks
Expand Down
4 changes: 3 additions & 1 deletion oracle/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/crypto/ed25519"
"github.com/cometbft/cometbft/crypto/sr25519"
"github.com/cometbft/cometbft/proxy"
"github.com/sirupsen/logrus"

Check failure on line 12 in oracle/reactor.go

View workflow job for this annotation

GitHub Actions / golangci-lint

import 'github.com/sirupsen/logrus' is not allowed from list 'main' (depguard)

// cfg "github.com/cometbft/cometbft/config"
Expand Down Expand Up @@ -48,7 +49,7 @@ type Reactor struct {
}

// NewReactor returns a new Reactor with the given config and mempool.
func NewReactor(config *config.OracleConfig, pubKey crypto.PubKey, privValidator types.PrivValidator) *Reactor {
func NewReactor(config *config.OracleConfig, pubKey crypto.PubKey, privValidator types.PrivValidator, proxyApp proxy.AppConnConsensus) *Reactor {
gossipVoteBuffer := &oracletypes.GossipVoteBuffer{
Buffer: make(map[string]*oracleproto.GossipVote),
}
Expand All @@ -64,6 +65,7 @@ func NewReactor(config *config.OracleConfig, pubKey crypto.PubKey, privValidator
SignVotesChan: make(chan *oracleproto.Vote),
PubKey: pubKey,
PrivValidator: privValidator,
ProxyApp: proxyApp,
}

oracleR := &Reactor{
Expand Down
18 changes: 9 additions & 9 deletions oracle/service/runner/runner.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package runner

import (
"io/ioutil"
"context"
"io"
"net/http"
"time"

Expand All @@ -12,6 +13,7 @@ import (

"github.com/cometbft/cometbft/oracle/service/types"

abcitypes "github.com/cometbft/cometbft/abci/types"
oracleproto "github.com/cometbft/cometbft/proto/tendermint/oracle"
)

Expand Down Expand Up @@ -152,21 +154,19 @@ func Run(oracleInfo *types.OracleInfo) {
log.Info("[oracle] Service started.")
waitForGrpc(oracleInfo.Config.GrpcAddress)
waitForRestAPI(oracleInfo.Config.RestApiAddress)
count := 0
RunProcessSignVoteQueue(oracleInfo)
PruneUnsignedVoteBuffer(oracleInfo)
PruneGossipVoteBuffer(oracleInfo)
// start to take votes from app
for {
if count == 0 { // on init, and every minute
res, err := oracleInfo.ProxyApp.PrepareOracleVotes(context.Background(), &abcitypes.RequestPrepareOracleVotes{})
if err != nil {
log.Error(err)
}

time.Sleep(100 * time.Millisecond)
log.Infof("RESULTS: %v", res.Votes)

count++
if count > 600 { // 600 * 0.1s = 60s = every minute
count = 0
}
time.Sleep(100 * time.Millisecond)
}
}

Expand Down Expand Up @@ -240,7 +240,7 @@ func HTTPRequest(url string, timeout uint64) []byte {

defer response.Body.Close()

body, readErr := ioutil.ReadAll(response.Body)
body, readErr := io.ReadAll(response.Body)

if readErr != nil {
return []byte{}
Expand Down
2 changes: 2 additions & 0 deletions oracle/service/types/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/cometbft/cometbft/crypto"
cmtsync "github.com/cometbft/cometbft/libs/sync"
oracleproto "github.com/cometbft/cometbft/proto/tendermint/oracle"
"github.com/cometbft/cometbft/proxy"
"github.com/cometbft/cometbft/types"
)

Expand All @@ -17,6 +18,7 @@ type OracleInfo struct {
PubKey crypto.PubKey
PrivValidator types.PrivValidator
StopChannel chan int
ProxyApp proxy.AppConnConsensus
}

type UnsignedVotes struct {
Expand Down

0 comments on commit 617f655

Please sign in to comment.