The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/hmy/backend.go

105 lines
3.6 KiB

package hmy
import (
"math/big"
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types"
staking "github.com/harmony-one/harmony/staking/types"
)
// Harmony implements the Harmony full node service.
type Harmony struct {
// Channel for shutting down the service
shutdownChan chan bool // Channel for shutting down the Harmony
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
blockchain *core.BlockChain
beaconchain *core.BlockChain
txPool *core.TxPool
cxPool *core.CxPool
eventMux *event.TypeMux
// DB interfaces
chainDb ethdb.Database // Block chain database
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
APIBackend *APIBackend
nodeAPI NodeAPI
6 years ago
// aka network version, which is used to identify which network we are using
6 years ago
networkID uint64
5 years ago
// RPCGasCap is the global gas cap for eth-call variants.
RPCGasCap *big.Int `toml:",omitempty"`
shardID uint32
}
// NodeAPI is the list of functions from node used to call rpc apis.
type NodeAPI interface {
AddPendingStakingTransaction(*staking.StakingTransaction) error
AddPendingTransaction(newTx *types.Transaction) error
Blockchain() *core.BlockChain
Beaconchain() *core.BlockChain
GetBalanceOfAddress(address common.Address) (*big.Int, error)
GetNonceOfAddress(address common.Address) uint64
GetTransactionsHistory(address, txType, order string) ([]common.Hash, error)
GetStakingTransactionsHistory(address, txType, order string) ([]common.Hash, error)
GetTransactionsCount(address, txType string) (uint64, error)
GetStakingTransactionsCount(address, txType string) (uint64, error)
IsCurrentlyLeader() bool
Fix error sink msg duplication & false positives (#2924) * [types] Add TransactionErrorSink to report failed txs [node] Create ErrorSink handler for unique error msgs Implemented with a LRU cache. [node] Rename ErrorSink to TransactionErrorSink * Rename RPCTransactionError to TransactionError [node] Make tx error sink not return err on Add & Remove [node] Make tx errorSink Contains check take string as tx hash param [errorsink] Move tx error sink into errorsink pkg [errorsink] Rename Errors and Count methods [errorsink] Rename NewTransactionErrorSink to NewTransactionSink [types] Move error sink to core/types * Rename NewTransactionSink to NewTransactionErrorSink * [types] Fix log msg for unfound errors * [types] Rename TransactionError to TransactionErrorReport * [core] Remove RPCTransactionError & refactor tx_pool to use TxErrorSink * [staking] Remove RPCTransactionError * [node] Refactor tx_pool init to use new TxErrorSink * [main] Construct transaction error sink before initing the node * [node] Refactor error sink reporting at RPC layer * [rpc] Refactor returned type of ErrorSink RPCs to 1 type * [core] Remove tx from TxErrorSink on Add to tx_pool * [types] Make NewTransactionErrorSink not return err * [node] Make node.New create error sink * [cmd] Revert to origin main.go * [core] Add TxErrorSink unit test & fix bad ErrExcessiveBLSKeys in tests * [testnet config] Change testnet config to allow for 5*4 external keys * [cmd] Revert main.go to original node instantiation * [rpc] Add GetPoolStats rpc to fetch pending and queued tx counts
5 years ago
ReportStakingErrorSink() types.TransactionErrorReports
ReportPlainErrorSink() types.TransactionErrorReports
PendingCXReceipts() []*types.CXReceiptsProof
GetNodeBootTime() int64
PeerConnectivity() (int, int, int)
}
// New creates a new Harmony object (including the
// initialisation of the common Harmony object)
func New(
nodeAPI NodeAPI, txPool *core.TxPool,
cxPool *core.CxPool, eventMux *event.TypeMux, shardID uint32,
) (*Harmony, error) {
chainDb := nodeAPI.Blockchain().ChainDB()
hmy := &Harmony{
shutdownChan: make(chan bool),
bloomRequests: make(chan chan *bloombits.Retrieval),
blockchain: nodeAPI.Blockchain(),
beaconchain: nodeAPI.Beaconchain(),
txPool: txPool,
cxPool: cxPool,
eventMux: eventMux,
chainDb: chainDb,
nodeAPI: nodeAPI,
networkID: 1, // TODO(ricl): this should be from config
shardID: shardID,
}
hmy.APIBackend = &APIBackend{hmy: hmy,
5 years ago
TotalStakingCache: struct {
sync.Mutex
BlockHeight int64
TotalStaking *big.Int
}{
BlockHeight: -1,
TotalStaking: big.NewInt(0),
},
}
return hmy, nil
}
// TxPool ...
func (s *Harmony) TxPool() *core.TxPool { return s.txPool }
// CxPool is used to store the blockHashes, where the corresponding block contains the cross shard receipts to be sent
func (s *Harmony) CxPool() *core.CxPool { return s.cxPool }
// BlockChain ...
func (s *Harmony) BlockChain() *core.BlockChain { return s.blockchain }
6 years ago
//BeaconChain ...
func (s *Harmony) BeaconChain() *core.BlockChain { return s.beaconchain }
6 years ago
// NetVersion returns the network version, i.e. network ID identifying which network we are using
6 years ago
func (s *Harmony) NetVersion() uint64 { return s.networkID }