mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 11:32:09 +00:00
Merge branch 'master' into construct-collation
Former-commit-id: 74b350ce5e3ff691d96619841d8c79dd8bb3fc31 [formerly 74164493417986920fe40d0543335046d85fd9fd] Former-commit-id: b487569e8cf816856c37d9d7c74244cf1e9a057c
This commit is contained in:
commit
5f7237a468
@ -536,7 +536,7 @@ var (
|
||||
// Sharding Settings
|
||||
DepositFlag = cli.BoolFlag{
|
||||
Name: "deposit",
|
||||
Usage: "To become a notary in a sharding node, " + new(big.Int).Div(shardparams.DefaultShardConfig.NotaryDeposit, new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)).String() + " ETH will be deposited into SMC",
|
||||
Usage: "To become a notary in a sharding node, " + new(big.Int).Div(shardparams.DefaultConfig.NotaryDeposit, new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)).String() + " ETH will be deposited into SMC",
|
||||
}
|
||||
ActorFlag = cli.StringFlag{
|
||||
Name: "actor",
|
||||
|
@ -68,7 +68,7 @@ func deploySMCContract(backend *backends.SimulatedBackend, key *ecdsa.PrivateKey
|
||||
|
||||
// fastForward is a helper function to skip through n period.
|
||||
func (s *smcTestHelper) fastForward(p int) {
|
||||
for i := 0; i < p*int(params.DefaultShardConfig.PeriodLength); i++ {
|
||||
for i := 0; i < p*int(params.DefaultConfig.PeriodLength); i++ {
|
||||
s.backend.Commit()
|
||||
}
|
||||
}
|
||||
@ -168,7 +168,7 @@ func (s *smcTestHelper) addHeader(a *testAccount, shard *big.Int, period *big.In
|
||||
|
||||
// Filter SMC logs by headerAdded.
|
||||
shardIndex := []*big.Int{shard}
|
||||
logPeriod := uint64(period.Int64() * params.DefaultShardConfig.PeriodLength)
|
||||
logPeriod := uint64(period.Int64() * params.DefaultConfig.PeriodLength)
|
||||
log, err := s.smc.FilterHeaderAdded(&bind.FilterOpts{Start: logPeriod}, shardIndex)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -200,7 +200,7 @@ func (s *smcTestHelper) submitVote(a *testAccount, shard *big.Int, period *big.I
|
||||
}
|
||||
// Filter SMC logs by submitVote.
|
||||
shardIndex := []*big.Int{shard}
|
||||
logPeriod := uint64(period.Int64() * params.DefaultShardConfig.PeriodLength)
|
||||
logPeriod := uint64(period.Int64() * params.DefaultConfig.PeriodLength)
|
||||
log, err := s.smc.FilterVoteSubmitted(&bind.FilterOpts{Start: logPeriod}, shardIndex)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -377,7 +377,7 @@ func TestNotaryRelease(t *testing.T) {
|
||||
}
|
||||
|
||||
// Fast forward until lockup ends.
|
||||
s.fastForward(int(params.DefaultShardConfig.NotaryLockupLength + 1))
|
||||
s.fastForward(int(params.DefaultConfig.NotaryLockupLength + 1))
|
||||
|
||||
// Notary 0 releases.
|
||||
_, err = s.smc.ReleaseNotary(s.testAccounts[0].txOpts)
|
||||
|
@ -14,14 +14,6 @@ type Node interface {
|
||||
Register(constructor ServiceConstructor) error
|
||||
}
|
||||
|
||||
// ShardP2P defines an interface for a peer-to-peer service in a
|
||||
// sharded Ethereum blockchain.
|
||||
type ShardP2P interface{}
|
||||
|
||||
// TXPool defines an interface for a transaction pool service that handles
|
||||
// incoming shard transactions in the network.
|
||||
type TXPool interface{}
|
||||
|
||||
// Actor refers to either a notary, proposer, or observer in the sharding spec.
|
||||
type Actor interface {
|
||||
Service
|
||||
|
@ -24,16 +24,16 @@ func dialRPC(endpoint string) (*rpc.Client, error) {
|
||||
// initSMC initializes the sharding manager contract bindings.
|
||||
// If the SMC does not exist, it will be deployed.
|
||||
func initSMC(s *SMCClient) (*contracts.SMC, error) {
|
||||
b, err := s.client.CodeAt(context.Background(), params.DefaultShardConfig.SMCAddress, nil)
|
||||
b, err := s.client.CodeAt(context.Background(), params.DefaultConfig.SMCAddress, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get contract code at %s: %v", params.DefaultShardConfig.SMCAddress.Hex(), err)
|
||||
return nil, fmt.Errorf("unable to get contract code at %s: %v", params.DefaultConfig.SMCAddress.Hex(), err)
|
||||
}
|
||||
|
||||
// Deploy SMC for development only.
|
||||
// TODO: Separate contract deployment from the sharding node. It would only need to be deployed
|
||||
// once on the mainnet, so this code would not need to ship with the node.
|
||||
if len(b) == 0 {
|
||||
log.Info(fmt.Sprintf("No sharding manager contract found at %s. Deploying new contract.", params.DefaultShardConfig.SMCAddress.Hex()))
|
||||
log.Info(fmt.Sprintf("No sharding manager contract found at %s. Deploying new contract.", params.DefaultConfig.SMCAddress.Hex()))
|
||||
|
||||
txOps, err := s.CreateTXOpts(big.NewInt(0))
|
||||
if err != nil {
|
||||
@ -56,5 +56,5 @@ func initSMC(s *SMCClient) (*contracts.SMC, error) {
|
||||
return contract, nil
|
||||
}
|
||||
|
||||
return contracts.NewSMC(params.DefaultShardConfig.SMCAddress, s.client)
|
||||
return contracts.NewSMC(params.DefaultConfig.SMCAddress, s.client)
|
||||
}
|
||||
|
@ -12,22 +12,20 @@ import (
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/ethereum/go-ethereum/internal/debug"
|
||||
"github.com/ethereum/go-ethereum/sharding/notary"
|
||||
"github.com/ethereum/go-ethereum/sharding/observer"
|
||||
shardp2p "github.com/ethereum/go-ethereum/sharding/p2p"
|
||||
"github.com/ethereum/go-ethereum/sharding/proposer"
|
||||
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/sharding"
|
||||
"github.com/ethereum/go-ethereum/sharding/mainchain"
|
||||
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/internal/debug"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/sharding"
|
||||
"github.com/ethereum/go-ethereum/sharding/database"
|
||||
"github.com/ethereum/go-ethereum/sharding/mainchain"
|
||||
"github.com/ethereum/go-ethereum/sharding/notary"
|
||||
"github.com/ethereum/go-ethereum/sharding/observer"
|
||||
"github.com/ethereum/go-ethereum/sharding/p2p"
|
||||
"github.com/ethereum/go-ethereum/sharding/params"
|
||||
"github.com/ethereum/go-ethereum/sharding/proposer"
|
||||
"github.com/ethereum/go-ethereum/sharding/txpool"
|
||||
"gopkg.in/urfave/cli.v1"
|
||||
)
|
||||
@ -38,8 +36,8 @@ const shardChainDbName = "shardchaindata"
|
||||
// it contains APIs and fields that handle the different components of the sharded
|
||||
// Ethereum network.
|
||||
type ShardEthereum struct {
|
||||
shardConfig *params.ShardConfig // Holds necessary information to configure shard node.
|
||||
txPool *txpool.ShardTXPool // Defines the sharding-specific txpool. To be designed.
|
||||
shardConfig *params.Config // Holds necessary information to configure shards.
|
||||
txPool *txpool.TXPool // Defines the sharding-specific txpool. To be designed.
|
||||
actor sharding.Actor // Either notary, proposer, or observer.
|
||||
shardChainDb ethdb.Database // Access to the persistent db to store shard data.
|
||||
eventFeed *event.Feed // Used to enable P2P related interactions via different sharding actors.
|
||||
@ -90,7 +88,7 @@ func New(ctx *cli.Context) (*ShardEthereum, error) {
|
||||
shardEthereum.smcClient = smcClient
|
||||
|
||||
// Configure shardConfig by loading the default.
|
||||
shardEthereum.shardConfig = params.DefaultShardConfig
|
||||
shardEthereum.shardConfig = params.DefaultConfig
|
||||
|
||||
// Adds the initialized shardChainDb to the ShardEthereum instance.
|
||||
shardEthereum.shardChainDb = shardChainDb
|
||||
@ -187,12 +185,12 @@ func (s *ShardEthereum) Register(constructor sharding.ServiceConstructor) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// registerP2P attaches a shardp2p server to the ShardEthereum instance.
|
||||
// TODO: Design this shardp2p service and the methods it should expose as well as
|
||||
// registerP2P attaches a p2p server to the ShardEthereum instance.
|
||||
// TODO: Design this p2p service and the methods it should expose as well as
|
||||
// its event loop.
|
||||
func (s *ShardEthereum) registerP2P() error {
|
||||
return s.Register(func(ctx *sharding.ServiceContext) (sharding.Service, error) {
|
||||
return shardp2p.NewServer()
|
||||
return p2p.NewServer()
|
||||
})
|
||||
}
|
||||
|
||||
@ -206,23 +204,23 @@ func (s *ShardEthereum) registerTXPool(actor string) error {
|
||||
return nil
|
||||
}
|
||||
return s.Register(func(ctx *sharding.ServiceContext) (sharding.Service, error) {
|
||||
var p2p *shardp2p.Server
|
||||
var p2p *p2p.Server
|
||||
ctx.RetrieveService(&p2p)
|
||||
return txpool.NewShardTXPool(p2p)
|
||||
return txpool.NewTXPool(p2p)
|
||||
})
|
||||
}
|
||||
|
||||
// Registers the actor according to CLI flags. Either notary/proposer/observer.
|
||||
func (s *ShardEthereum) registerActorService(config *params.ShardConfig, actor string, shardID int) error {
|
||||
func (s *ShardEthereum) registerActorService(config *params.Config, actor string, shardID int) error {
|
||||
return s.Register(func(ctx *sharding.ServiceContext) (sharding.Service, error) {
|
||||
|
||||
var p2p *shardp2p.Server
|
||||
var p2p *p2p.Server
|
||||
ctx.RetrieveService(&p2p)
|
||||
|
||||
if actor == "notary" {
|
||||
return notary.NewNotary(config, s.smcClient, p2p, s.shardChainDb)
|
||||
} else if actor == "proposer" {
|
||||
var txPool *txpool.ShardTXPool
|
||||
var txPool *txpool.TXPool
|
||||
ctx.RetrieveService(&txPool)
|
||||
return proposer.NewProposer(config, s.smcClient, p2p, txPool, s.shardChainDb, shardID)
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/sharding/mainchain"
|
||||
sparams "github.com/ethereum/go-ethereum/sharding/params"
|
||||
shardparams "github.com/ethereum/go-ethereum/sharding/params"
|
||||
)
|
||||
|
||||
// SubscribeBlockHeaders checks incoming block headers and determines if
|
||||
@ -136,7 +136,7 @@ func submitCollation(shardID int64) error {
|
||||
// joinNotaryPool checks if the deposit flag is true and the account is a
|
||||
// notary in the SMC. If the account is not in the set, it will deposit ETH
|
||||
// into contract.
|
||||
func joinNotaryPool(config *sparams.ShardConfig, client mainchain.Client) error {
|
||||
func joinNotaryPool(config *shardparams.Config, client mainchain.Client) error {
|
||||
if !client.DepositFlag() {
|
||||
return errors.New("joinNotaryPool called when deposit flag was not set")
|
||||
}
|
||||
@ -146,7 +146,7 @@ func joinNotaryPool(config *sparams.ShardConfig, client mainchain.Client) error
|
||||
}
|
||||
|
||||
log.Info("Joining notary pool")
|
||||
txOps, err := client.CreateTXOpts(config.NotaryDeposit)
|
||||
txOps, err := client.CreateTXOpts(shardparams.DefaultConfig.NotaryDeposit)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to initiate the deposit transaction: %v", err)
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/sharding"
|
||||
"github.com/ethereum/go-ethereum/sharding/mainchain"
|
||||
"github.com/ethereum/go-ethereum/sharding/p2p"
|
||||
"github.com/ethereum/go-ethereum/sharding/params"
|
||||
)
|
||||
|
||||
@ -16,15 +16,15 @@ import (
|
||||
// in a sharded system. Must satisfy the Service interface defined in
|
||||
// sharding/service.go.
|
||||
type Notary struct {
|
||||
config *params.ShardConfig
|
||||
config *params.Config
|
||||
smcClient *mainchain.SMCClient
|
||||
shardp2p sharding.ShardP2P
|
||||
p2p *p2p.Server
|
||||
shardChainDb ethdb.Database
|
||||
}
|
||||
|
||||
// NewNotary creates a new notary instance.
|
||||
func NewNotary(config *params.ShardConfig, smcClient *mainchain.SMCClient, shardp2p sharding.ShardP2P, shardChainDb ethdb.Database) (*Notary, error) {
|
||||
return &Notary{config, smcClient, shardp2p, shardChainDb}, nil
|
||||
func NewNotary(config *params.Config, smcClient *mainchain.SMCClient, p2p *p2p.Server, shardChainDb ethdb.Database) (*Notary, error) {
|
||||
return &Notary{config, smcClient, p2p, shardChainDb}, nil
|
||||
}
|
||||
|
||||
// Start the main routine for a notary.
|
||||
|
@ -127,7 +127,7 @@ func TestIsAccountInNotaryPool(t *testing.T) {
|
||||
|
||||
txOpts := transactOpts()
|
||||
// deposit in notary pool, then it should return true.
|
||||
txOpts.Value = params.DefaultShardConfig.NotaryDeposit
|
||||
txOpts.Value = params.DefaultConfig.NotaryDeposit
|
||||
if _, err := smc.RegisterNotary(txOpts); err != nil {
|
||||
t.Fatalf("Failed to deposit: %v", err)
|
||||
}
|
||||
@ -154,13 +154,13 @@ func TestJoinNotaryPool(t *testing.T) {
|
||||
}
|
||||
|
||||
client.SetDepositFlag(false)
|
||||
err = joinNotaryPool(params.DefaultShardConfig, client)
|
||||
err = joinNotaryPool(params.DefaultConfig, client)
|
||||
if err == nil {
|
||||
t.Error("Joined notary pool while --deposit was not present")
|
||||
}
|
||||
|
||||
client.SetDepositFlag(true)
|
||||
err = joinNotaryPool(params.DefaultShardConfig, client)
|
||||
err = joinNotaryPool(params.DefaultConfig, client)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -176,7 +176,7 @@ func TestJoinNotaryPool(t *testing.T) {
|
||||
}
|
||||
|
||||
// Trying to join while deposited should do nothing
|
||||
err = joinNotaryPool(params.DefaultShardConfig, client)
|
||||
err = joinNotaryPool(params.DefaultConfig, client)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -7,21 +7,21 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/sharding"
|
||||
"github.com/ethereum/go-ethereum/sharding/p2p"
|
||||
)
|
||||
|
||||
// Observer holds functionality required to run an observer service
|
||||
// in a sharded system. Must satisfy the Service interface defined in
|
||||
// sharding/service.go.
|
||||
type Observer struct {
|
||||
shardp2p sharding.ShardP2P
|
||||
p2p *p2p.Server
|
||||
shardChainDb ethdb.Database
|
||||
shardID int
|
||||
}
|
||||
|
||||
// NewObserver creates a new observer instance.
|
||||
func NewObserver(shardp2p sharding.ShardP2P, shardChainDb ethdb.Database, shardID int) (*Observer, error) {
|
||||
return &Observer{shardp2p, shardChainDb, shardID}, nil
|
||||
func NewObserver(p2p *p2p.Server, shardChainDb ethdb.Database, shardID int) (*Observer, error) {
|
||||
return &Observer{p2p, shardChainDb, shardID}, nil
|
||||
}
|
||||
|
||||
// Start the main routine for an observer.
|
||||
|
@ -4,5 +4,5 @@ import (
|
||||
"github.com/ethereum/go-ethereum/sharding"
|
||||
)
|
||||
|
||||
// Verifies that Server implements the ShardP2P interface.
|
||||
var _ = sharding.ShardP2P(&Server{})
|
||||
// Ensure that server implements service.
|
||||
var _ = sharding.Service(&Server{})
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Package params defines important configuration options to be used when instantiating
|
||||
// objects within the sharding package. For example, it defines objects such as a
|
||||
// ShardConfig that will be useful when creating new shard instances.
|
||||
// Config that will be useful when creating new shard instances.
|
||||
package params
|
||||
|
||||
import (
|
||||
@ -9,8 +9,8 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// DefaultShardConfig contains default configs for node to use in the sharded universe
|
||||
var DefaultShardConfig = &ShardConfig{
|
||||
// DefaultConfig contains default configs for node to use in the sharded universe.
|
||||
var DefaultConfig = &Config{
|
||||
SMCAddress: common.HexToAddress("0x0"),
|
||||
PeriodLength: 5,
|
||||
NotaryDeposit: new(big.Int).Exp(big.NewInt(10), big.NewInt(21), nil), // 1000 ETH
|
||||
@ -21,11 +21,11 @@ var DefaultShardConfig = &ShardConfig{
|
||||
NotaryChallengePeriod: 25,
|
||||
}
|
||||
|
||||
// DefaultShardChainConfig contains default chain configs of an individual shard.
|
||||
var DefaultShardChainConfig = &ShardChainConfig{}
|
||||
// DefaultChainConfig contains default chain configs of an individual shard.
|
||||
var DefaultChainConfig = &ChainConfig{}
|
||||
|
||||
// ShardConfig contains configs for node to participate in the sharded universe.
|
||||
type ShardConfig struct {
|
||||
// Config contains configs for node to participate in the sharded universe.
|
||||
type Config struct {
|
||||
SMCAddress common.Address // SMCAddress is the address of SMC in mainchain.
|
||||
PeriodLength int64 // PeriodLength is num of blocks in period.
|
||||
NotaryDeposit *big.Int // NotaryDeposit is a required deposit size in wei.
|
||||
@ -36,5 +36,5 @@ type ShardConfig struct {
|
||||
NotaryChallengePeriod int64 // NotaryChallengePeriod is the duration a notary has to store collations for.
|
||||
}
|
||||
|
||||
// ShardChainConfig contains chain config of an individual shard. Still to be designed.
|
||||
type ShardChainConfig struct{}
|
||||
// ChainConfig contains chain config of an individual shard. Still to be designed.
|
||||
type ChainConfig struct{}
|
||||
|
@ -10,43 +10,43 @@ func TestNotaryDeposit(t *testing.T) {
|
||||
if !err {
|
||||
t.Fatalf("Failed to setup test")
|
||||
}
|
||||
if DefaultShardConfig.NotaryDeposit.Cmp(want) != 0 {
|
||||
t.Errorf("Notary deposit size incorrect. Wanted %d, got %d", want, DefaultShardConfig.NotaryDeposit)
|
||||
if DefaultConfig.NotaryDeposit.Cmp(want) != 0 {
|
||||
t.Errorf("Notary deposit size incorrect. Wanted %d, got %d", want, DefaultConfig.NotaryDeposit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeriodLength(t *testing.T) {
|
||||
if DefaultShardConfig.PeriodLength != 5 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 5, DefaultShardConfig.PeriodLength)
|
||||
if DefaultConfig.PeriodLength != 5 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 5, DefaultConfig.PeriodLength)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotaryLockupLength(t *testing.T) {
|
||||
if DefaultShardConfig.NotaryLockupLength != 16128 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 16128, DefaultShardConfig.NotaryLockupLength)
|
||||
if DefaultConfig.NotaryLockupLength != 16128 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 16128, DefaultConfig.NotaryLockupLength)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProposerLockupLength(t *testing.T) {
|
||||
if DefaultShardConfig.ProposerLockupLength != 48 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 48, DefaultShardConfig.ProposerLockupLength)
|
||||
if DefaultConfig.ProposerLockupLength != 48 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 48, DefaultConfig.ProposerLockupLength)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotaryCommitteeSize(t *testing.T) {
|
||||
if DefaultShardConfig.NotaryCommitteeSize != 135 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 135, DefaultShardConfig.NotaryCommitteeSize)
|
||||
if DefaultConfig.NotaryCommitteeSize != 135 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 135, DefaultConfig.NotaryCommitteeSize)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotaryQuorumSize(t *testing.T) {
|
||||
if DefaultShardConfig.NotaryQuorumSize != 90 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 90, DefaultShardConfig.NotaryQuorumSize)
|
||||
if DefaultConfig.NotaryQuorumSize != 90 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 90, DefaultConfig.NotaryQuorumSize)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotaryChallengePeriod(t *testing.T) {
|
||||
if DefaultShardConfig.NotaryChallengePeriod != 25 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 25, DefaultShardConfig.NotaryChallengePeriod)
|
||||
if DefaultConfig.NotaryChallengePeriod != 25 {
|
||||
t.Errorf("Shard count incorrect. Wanted %d, got %d", 25, DefaultConfig.NotaryChallengePeriod)
|
||||
}
|
||||
}
|
||||
|
@ -12,28 +12,29 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/sharding"
|
||||
"github.com/ethereum/go-ethereum/sharding/mainchain"
|
||||
"github.com/ethereum/go-ethereum/sharding/p2p"
|
||||
"github.com/ethereum/go-ethereum/sharding/params"
|
||||
"github.com/ethereum/go-ethereum/sharding/txpool"
|
||||
)
|
||||
|
||||
// Proposer holds functionality required to run a collation proposer
|
||||
// in a sharded system. Must satisfy the Service interface defined in
|
||||
// sharding/service.go.
|
||||
type Proposer struct {
|
||||
config *params.ShardConfig
|
||||
config *params.Config
|
||||
client *mainchain.SMCClient
|
||||
shardp2p sharding.ShardP2P
|
||||
txpool sharding.TXPool
|
||||
p2p *p2p.Server
|
||||
txpool *txpool.TXPool
|
||||
shardChainDb ethdb.Database
|
||||
shardID int
|
||||
}
|
||||
|
||||
// NewProposer creates a struct instance of a proposer service.
|
||||
// It will have access to a mainchain client, a shardp2p network,
|
||||
// It will have access to a mainchain client, a p2p network,
|
||||
// and a shard transaction pool.
|
||||
func NewProposer(config *params.ShardConfig, client *mainchain.SMCClient, shardp2p sharding.ShardP2P, txpool sharding.TXPool, shardChainDb ethdb.Database, shardID int) (*Proposer, error) {
|
||||
return &Proposer{config, client, shardp2p, txpool, shardChainDb, shardID}, nil
|
||||
func NewProposer(config *params.Config, client *mainchain.SMCClient, p2p *p2p.Server, txpool *txpool.TXPool, shardChainDb ethdb.Database, shardID int) (*Proposer, error) {
|
||||
return &Proposer{config, client, p2p, txpool, shardChainDb, shardID}, nil
|
||||
}
|
||||
|
||||
// Start the main loop for proposing collations.
|
||||
|
@ -128,7 +128,7 @@ func TestCreateCollation(t *testing.T) {
|
||||
}
|
||||
|
||||
// fast forward to 2nd period.
|
||||
for i := 0; i < 2*int(params.DefaultShardConfig.PeriodLength); i++ {
|
||||
for i := 0; i < 2*int(params.DefaultConfig.PeriodLength); i++ {
|
||||
backend.Commit()
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ func TestAddCollation(t *testing.T) {
|
||||
}
|
||||
|
||||
// fast forward to next period.
|
||||
for i := 0; i < int(params.DefaultShardConfig.PeriodLength); i++ {
|
||||
for i := 0; i < int(params.DefaultConfig.PeriodLength); i++ {
|
||||
backend.Commit()
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ func TestCheckCollation(t *testing.T) {
|
||||
t.Errorf("Create collation failed: %v", err)
|
||||
}
|
||||
|
||||
for i := 0; i < int(params.DefaultShardConfig.PeriodLength); i++ {
|
||||
for i := 0; i < int(params.DefaultConfig.PeriodLength); i++ {
|
||||
backend.Commit()
|
||||
}
|
||||
|
||||
|
@ -3,26 +3,26 @@ package txpool
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/sharding"
|
||||
"github.com/ethereum/go-ethereum/sharding/p2p"
|
||||
)
|
||||
|
||||
// ShardTXPool handles a transaction pool for a sharded system.
|
||||
type ShardTXPool struct {
|
||||
p2p sharding.ShardP2P
|
||||
// TXPool handles a transaction pool for a sharded system.
|
||||
type TXPool struct {
|
||||
p2p *p2p.Server
|
||||
}
|
||||
|
||||
// NewShardTXPool creates a new observer instance.
|
||||
func NewShardTXPool(p2p sharding.ShardP2P) (*ShardTXPool, error) {
|
||||
return &ShardTXPool{p2p}, nil
|
||||
// NewTXPool creates a new observer instance.
|
||||
func NewTXPool(p2p *p2p.Server) (*TXPool, error) {
|
||||
return &TXPool{p2p}, nil
|
||||
}
|
||||
|
||||
// Start the main routine for a shard transaction pool.
|
||||
func (p *ShardTXPool) Start() {
|
||||
func (p *TXPool) Start() {
|
||||
log.Info("Starting shard txpool service")
|
||||
}
|
||||
|
||||
// Stop the main loop for a transaction pool in the shard network.
|
||||
func (p *ShardTXPool) Stop() error {
|
||||
func (p *TXPool) Stop() error {
|
||||
log.Info("Stopping shard txpool service")
|
||||
return nil
|
||||
}
|
||||
|
@ -2,5 +2,5 @@ package txpool
|
||||
|
||||
import "github.com/ethereum/go-ethereum/sharding"
|
||||
|
||||
// Verifies that ShardTXPool implements the TXPool interface.
|
||||
var _ = sharding.TXPool(&ShardTXPool{})
|
||||
// Verifies that TXPool implements the Service interface.
|
||||
var _ = sharding.Service(&TXPool{})
|
||||
|
Loading…
Reference in New Issue
Block a user