diff --git a/.gitignore b/.gitignore index 2c69fbb..8e77007 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ eth-contracts/node_modules /.dione-config.toml /.dione-config-2.toml /.dione-config-3.toml +/.dione-config-4.toml +.bootstrap_privkey eth-contracts/build \ No newline at end of file diff --git a/consensus/miner.go b/consensus/miner.go index 606ac1c..3326c46 100644 --- a/consensus/miner.go +++ b/consensus/miner.go @@ -6,7 +6,7 @@ import ( "sync" "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" solTypes "github.com/Secured-Finance/dione/solana/types" diff --git a/ethclient/ethereum.go b/ethclient/ethereum.go index 3ce58b8..e0c542e 100644 --- a/ethclient/ethereum.go +++ b/ethclient/ethereum.go @@ -7,7 +7,7 @@ import ( "github.com/Secured-Finance/dione/contracts/aggregator" "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/common" "github.com/ethereum/go-ethereum/crypto" @@ -81,8 +81,8 @@ func (c *EthereumClient) Initialize(ctx context.Context, url, privateKey, oracle TransactOpts: bind.TransactOpts{ From: authTransactor.From, Signer: authTransactor.Signer, - GasLimit: 0, // 0 automatically estimates gas limit - GasPrice: nil, // nil automatically suggests gas price + GasLimit: 200000, // 0 automatically estimates gas limit + GasPrice: nil, // nil automatically suggests gas price Context: context.Background(), }, } @@ -96,8 +96,8 @@ func (c *EthereumClient) Initialize(ctx context.Context, url, privateKey, oracle TransactOpts: bind.TransactOpts{ From: authTransactor.From, Signer: authTransactor.Signer, - GasLimit: 0, // 0 automatically estimates gas limit - GasPrice: nil, // nil automatically suggests gas price + GasLimit: 200000, // 0 automatically estimates gas limit + GasPrice: nil, // nil automatically suggests gas price Context: context.Background(), }, } @@ -111,8 +111,8 @@ func (c *EthereumClient) Initialize(ctx context.Context, url, privateKey, oracle TransactOpts: bind.TransactOpts{ From: authTransactor.From, Signer: authTransactor.Signer, - GasLimit: 0, // 0 automatically estimates gas limit - GasPrice: nil, // nil automatically suggests gas price + GasLimit: 200000, // 0 automatically estimates gas limit + GasPrice: big.NewInt(1860127603), // nil automatically suggests gas price Context: context.Background(), }, } diff --git a/node/ethereum.go b/node/ethereum.go index 819f09b..6dcd5b3 100644 --- a/node/ethereum.go +++ b/node/ethereum.go @@ -3,7 +3,6 @@ package node import ( "context" - "github.com/Secured-Finance/dione/consensus" "github.com/sirupsen/logrus" ) @@ -23,21 +22,24 @@ func (n *Node) subscribeOnEthContracts(ctx context.Context) { if err != nil { logrus.Fatal("Error with mining algorithm, exiting... ", err) } + if task == nil { + continue + } logrus.Info("BlockHash for Solana transaction: ", task.BlockHash) logrus.Info("Started new consensus round with ID: ", task.BlockHash) n.ConsensusManager.NewTestConsensus(string(task.BlockHash), task.BlockHash, func(finalData string) { 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("Submitting on-chain result: ", task.BlockHash, "for consensus ID: ", task.BlockHash) - 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) + if task.Miner == n.Host.ID() { + 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) + } } - } + }) } case <-ctx.Done(): break EventLoop diff --git a/node/node.go b/node/node.go index 7f30ad4..6a3617e 100644 --- a/node/node.go +++ b/node/node.go @@ -5,6 +5,8 @@ import ( "crypto/rand" "flag" "fmt" + "io/ioutil" + "os" "time" "github.com/Secured-Finance/dione/solana" @@ -31,7 +33,7 @@ import ( ) const ( - DefaultPEXUpdateTime = 1 * time.Minute + DefaultPEXUpdateTime = 6 * time.Second ) type Node struct { @@ -240,22 +242,37 @@ func Start() error { if *verbose { logrus.SetLevel(logrus.DebugLevel) } else { - logrus.SetLevel(logrus.InfoLevel) + logrus.SetLevel(logrus.DebugLevel) } if err != nil { logrus.Panic(err) } - privKey, err := generatePrivateKey() - if err != nil { - logrus.Fatal(err) + var privateKey crypto.PrivKey + + if node.Config.IsBootstrap { + if _, err := os.Stat(".bootstrap_privkey"); os.IsNotExist(err) { + privateKey, err = generatePrivateKey() + if err != nil { + 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()) node.GlobalCtx = ctx node.GlobalCtxCancel = ctxCancel - node.setupNode(ctx, privKey, DefaultPEXUpdateTime) + node.setupNode(ctx, privateKey, DefaultPEXUpdateTime) for { select { case <-ctx.Done(): diff --git a/pb/pubsub_router.go b/pb/pubsub_router.go index 2367807..e3aecfd 100644 --- a/pb/pubsub_router.go +++ b/pb/pubsub_router.go @@ -30,7 +30,7 @@ func NewPubSubRouter(h host.Host, oracleTopic string) *PubSubRouter { handlers: make(map[string][]Handler), } - pb, err := pubsub.NewGossipSub( + pb, err := pubsub.NewFloodSub( context.TODO(), psr.node, //pubsub.WithMessageSigning(true), //pubsub.WithStrictSignatureVerification(true),