Fix pubsub issues

This commit is contained in:
ChronosX88 2020-11-15 14:11:07 +04:00
parent 2526f65825
commit b04ba982a9
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
6 changed files with 44 additions and 23 deletions

2
.gitignore vendored
View File

@ -22,4 +22,6 @@ eth-contracts/node_modules
/.dione-config.toml /.dione-config.toml
/.dione-config-2.toml /.dione-config-2.toml
/.dione-config-3.toml /.dione-config-3.toml
/.dione-config-4.toml
.bootstrap_privkey
eth-contracts/build eth-contracts/build

View File

@ -6,7 +6,7 @@ import (
"sync" "sync"
"github.com/Secured-Finance/dione/beacon" "github.com/Secured-Finance/dione/beacon"
"github.com/Secured-Finance/dione/contracts/oracleEmitter" oracleEmitter "github.com/Secured-Finance/dione/contracts/oracleemitter"
"github.com/Secured-Finance/dione/solana" "github.com/Secured-Finance/dione/solana"
solTypes "github.com/Secured-Finance/dione/solana/types" solTypes "github.com/Secured-Finance/dione/solana/types"

View File

@ -7,7 +7,7 @@ import (
"github.com/Secured-Finance/dione/contracts/aggregator" "github.com/Secured-Finance/dione/contracts/aggregator"
"github.com/Secured-Finance/dione/contracts/dioneStaking" "github.com/Secured-Finance/dione/contracts/dioneStaking"
stakingContract "github.com/Secured-Finance/dione/contracts/dioneStaking" stakingContract "github.com/Secured-Finance/dione/contracts/dioneStaking"
oracleEmitter "github.com/Secured-Finance/dione/contracts/oracleEmitter" oracleEmitter "github.com/Secured-Finance/dione/contracts/oracleemitter"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
@ -81,7 +81,7 @@ func (c *EthereumClient) Initialize(ctx context.Context, url, privateKey, oracle
TransactOpts: bind.TransactOpts{ TransactOpts: bind.TransactOpts{
From: authTransactor.From, From: authTransactor.From,
Signer: authTransactor.Signer, Signer: authTransactor.Signer,
GasLimit: 0, // 0 automatically estimates gas limit GasLimit: 200000, // 0 automatically estimates gas limit
GasPrice: nil, // nil automatically suggests gas price GasPrice: nil, // nil automatically suggests gas price
Context: context.Background(), Context: context.Background(),
}, },
@ -96,7 +96,7 @@ func (c *EthereumClient) Initialize(ctx context.Context, url, privateKey, oracle
TransactOpts: bind.TransactOpts{ TransactOpts: bind.TransactOpts{
From: authTransactor.From, From: authTransactor.From,
Signer: authTransactor.Signer, Signer: authTransactor.Signer,
GasLimit: 0, // 0 automatically estimates gas limit GasLimit: 200000, // 0 automatically estimates gas limit
GasPrice: nil, // nil automatically suggests gas price GasPrice: nil, // nil automatically suggests gas price
Context: context.Background(), Context: context.Background(),
}, },
@ -111,8 +111,8 @@ func (c *EthereumClient) Initialize(ctx context.Context, url, privateKey, oracle
TransactOpts: bind.TransactOpts{ TransactOpts: bind.TransactOpts{
From: authTransactor.From, From: authTransactor.From,
Signer: authTransactor.Signer, Signer: authTransactor.Signer,
GasLimit: 0, // 0 automatically estimates gas limit GasLimit: 200000, // 0 automatically estimates gas limit
GasPrice: nil, // nil automatically suggests gas price GasPrice: big.NewInt(1860127603), // nil automatically suggests gas price
Context: context.Background(), Context: context.Background(),
}, },
} }

View File

@ -3,7 +3,6 @@ package node
import ( import (
"context" "context"
"github.com/Secured-Finance/dione/consensus"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -23,21 +22,24 @@ func (n *Node) subscribeOnEthContracts(ctx context.Context) {
if err != nil { if err != nil {
logrus.Fatal("Error with mining algorithm, exiting... ", err) logrus.Fatal("Error with mining algorithm, exiting... ", err)
} }
if task == nil {
continue
}
logrus.Info("BlockHash for Solana transaction: ", task.BlockHash) logrus.Info("BlockHash for Solana transaction: ", task.BlockHash)
logrus.Info("Started new consensus round with ID: ", task.BlockHash) logrus.Info("Started new consensus round with ID: ", task.BlockHash)
n.ConsensusManager.NewTestConsensus(string(task.BlockHash), task.BlockHash, func(finalData string) { n.ConsensusManager.NewTestConsensus(string(task.BlockHash), task.BlockHash, func(finalData string) {
if finalData != string(task.BlockHash) { if finalData != string(task.BlockHash) {
logrus.Warn("Expected final data to be %s, not %s", finalData) logrus.Warnf("Expected final data to be %s, not %s", task.BlockHash, finalData)
return
} }
})
if n.ConsensusManager.Consensuses[task.BlockHash].State == consensus.ConsensusCommitted {
logrus.Info("Consensus ID: ", task.BlockHash, " was successfull") logrus.Info("Consensus ID: ", task.BlockHash, " was successfull")
logrus.Info("Submitting on-chain result: ", task.BlockHash, "for consensus ID: ", task.BlockHash) logrus.Info("Submitting on-chain result: ", task.BlockHash, "for consensus ID: ", task.BlockHash)
if task.Miner == n.Host.ID() {
if err := n.Ethereum.SubmitRequestAnswer(event.RequestID, task.BlockHash, event.CallbackAddress, event.CallbackMethodID); err != nil { if err := n.Ethereum.SubmitRequestAnswer(event.RequestID, task.BlockHash, event.CallbackAddress, event.CallbackMethodID); err != nil {
logrus.Warn("Can't submit request to ethereum chain: ", err) logrus.Warn("Can't submit request to ethereum chain: ", err)
} }
} }
})
} }
case <-ctx.Done(): case <-ctx.Done():
break EventLoop break EventLoop

View File

@ -5,6 +5,8 @@ import (
"crypto/rand" "crypto/rand"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"os"
"time" "time"
"github.com/Secured-Finance/dione/solana" "github.com/Secured-Finance/dione/solana"
@ -31,7 +33,7 @@ import (
) )
const ( const (
DefaultPEXUpdateTime = 1 * time.Minute DefaultPEXUpdateTime = 6 * time.Second
) )
type Node struct { type Node struct {
@ -240,22 +242,37 @@ func Start() error {
if *verbose { if *verbose {
logrus.SetLevel(logrus.DebugLevel) logrus.SetLevel(logrus.DebugLevel)
} else { } else {
logrus.SetLevel(logrus.InfoLevel) logrus.SetLevel(logrus.DebugLevel)
} }
if err != nil { if err != nil {
logrus.Panic(err) logrus.Panic(err)
} }
privKey, err := generatePrivateKey() var privateKey crypto.PrivKey
if node.Config.IsBootstrap {
if _, err := os.Stat(".bootstrap_privkey"); os.IsNotExist(err) {
privateKey, err = generatePrivateKey()
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
f, _ := os.Create(".bootstrap_privkey")
r, _ := privateKey.Raw()
f.Write(r)
} else {
pkey, _ := ioutil.ReadFile(".bootstrap_privkey")
privateKey, _ = crypto.UnmarshalEd25519PrivateKey(pkey)
}
} else {
privateKey, err = generatePrivateKey()
}
ctx, ctxCancel := context.WithCancel(context.Background()) ctx, ctxCancel := context.WithCancel(context.Background())
node.GlobalCtx = ctx node.GlobalCtx = ctx
node.GlobalCtxCancel = ctxCancel node.GlobalCtxCancel = ctxCancel
node.setupNode(ctx, privKey, DefaultPEXUpdateTime) node.setupNode(ctx, privateKey, DefaultPEXUpdateTime)
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():

View File

@ -30,7 +30,7 @@ func NewPubSubRouter(h host.Host, oracleTopic string) *PubSubRouter {
handlers: make(map[string][]Handler), handlers: make(map[string][]Handler),
} }
pb, err := pubsub.NewGossipSub( pb, err := pubsub.NewFloodSub(
context.TODO(), context.TODO(),
psr.node, //pubsub.WithMessageSigning(true), psr.node, //pubsub.WithMessageSigning(true),
//pubsub.WithStrictSignatureVerification(true), //pubsub.WithStrictSignatureVerification(true),