mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-05 03:06:16 +00:00
oracle: integrate module in core and RPC
1. Initialization is performed via `Blockchain` methods. 2. Native Oracle contract updates list of oracle nodes and in-fly requests in `PostPersist`. 3. RPC uses Oracle module directly.
This commit is contained in:
parent
7e16bea126
commit
43e4d3af88
31 changed files with 590 additions and 44 deletions
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/capability"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"go.uber.org/atomic"
|
||||
"go.uber.org/zap"
|
||||
|
@ -82,6 +83,8 @@ type (
|
|||
|
||||
consensusStarted *atomic.Bool
|
||||
|
||||
oracle *oracle.Oracle
|
||||
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
|
@ -142,6 +145,29 @@ func newServerFromConstructors(config ServerConfig, chain blockchainer.Blockchai
|
|||
}
|
||||
})
|
||||
|
||||
if config.OracleCfg.Enabled {
|
||||
orcCfg := oracle.Config{
|
||||
Log: log,
|
||||
Network: config.Net,
|
||||
MainCfg: config.OracleCfg,
|
||||
Chain: chain,
|
||||
}
|
||||
orc, err := oracle.NewOracle(orcCfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't initialize Oracle module: %w", err)
|
||||
}
|
||||
orc.SetOnTransaction(func(tx *transaction.Transaction) {
|
||||
r := s.RelayTxn(tx)
|
||||
if r != RelaySucceed {
|
||||
orc.Log.Error("can't pool oracle tx",
|
||||
zap.String("hash", tx.Hash().StringLE()),
|
||||
zap.Uint8("reason", byte(r)))
|
||||
}
|
||||
})
|
||||
s.oracle = orc
|
||||
chain.SetOracle(orc)
|
||||
}
|
||||
|
||||
srv, err := newConsensus(consensus.Config{
|
||||
Logger: log,
|
||||
Broadcast: s.handleNewPayload,
|
||||
|
@ -203,6 +229,9 @@ func (s *Server) Start(errChan chan error) {
|
|||
s.initStaleMemPools()
|
||||
|
||||
go s.broadcastTxLoop()
|
||||
if s.oracle != nil {
|
||||
go s.oracle.Run()
|
||||
}
|
||||
go s.relayBlocksLoop()
|
||||
go s.bQueue.run()
|
||||
go s.transport.Accept()
|
||||
|
@ -222,9 +251,17 @@ func (s *Server) Shutdown() {
|
|||
p.Disconnect(errServerShutdown)
|
||||
}
|
||||
s.bQueue.discard()
|
||||
if s.oracle != nil {
|
||||
s.oracle.Shutdown()
|
||||
}
|
||||
close(s.quit)
|
||||
}
|
||||
|
||||
// GetOracle returns oracle module instance.
|
||||
func (s *Server) GetOracle() *oracle.Oracle {
|
||||
return s.oracle
|
||||
}
|
||||
|
||||
// UnconnectedPeers returns a list of peers that are in the discovery peer list
|
||||
// but are not connected to the server.
|
||||
func (s *Server) UnconnectedPeers() []string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue