Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
olegrok committed Jan 29, 2025
1 parent 0bd6aa7 commit 7ccd1e9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 54 deletions.
39 changes: 0 additions & 39 deletions nil/internal/collate/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package collate

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -41,7 +40,6 @@ type Params struct {

ZeroState string
ZeroStateConfig *execution.ZeroStateConfig
MainKeysOutPath string

Topology ShardTopology
}
Expand Down Expand Up @@ -109,43 +107,6 @@ func (s *Scheduler) Run(ctx context.Context, syncer *Syncer, consensus Consensus
}
}

func (s *Scheduler) generateZeroState(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, s.params.Timeout)
defer cancel()

roTx, err := s.txFabric.CreateRoTx(ctx)
if err != nil {
return err
}
defer roTx.Rollback()

if _, err := db.ReadLastBlockHash(roTx, s.params.ShardId); !errors.Is(err, db.ErrKeyNotFound) {
// error or nil if last block found
return err
}

if len(s.params.MainKeysOutPath) != 0 && s.params.ShardId == types.BaseShardId {
if err := execution.DumpMainKeys(s.params.MainKeysOutPath); err != nil {
return err
}
}

s.logger.Info().Msg("Generating zero-state...")

gen, err := execution.NewBlockGenerator(ctx, s.params.BlockGeneratorParams, s.txFabric)
if err != nil {
return err
}
defer gen.Rollback()

block, err := gen.GenerateZeroState(s.params.ZeroState, s.params.ZeroStateConfig)
if err != nil {
return err
}

return PublishBlock(ctx, s.networkManager, s.params.ShardId, &types.BlockWithExtractedData{Block: block})
}

func (s *Scheduler) BuildProposal(ctx context.Context) (*execution.Proposal, error) {
collator := newCollator(s.params, s.params.Topology, s.pool, s.logger)
proposal, err := collator.GenerateProposal(ctx, s.txFabric)
Expand Down
19 changes: 17 additions & 2 deletions nil/internal/collate/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,20 +363,35 @@ func (s *Syncer) saveDirectly(ctx context.Context, blocks []*types.BlockWithExtr
}

func (s *Syncer) generateZerostate(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, s.config.Timeout)
defer cancel()

if empty, err := s.shardIsEmpty(ctx); err != nil {
return err
} else if !empty {
return nil
}

if len(s.config.BlockGeneratorParams.MainKeysOutPath) != 0 && s.config.ShardId == types.BaseShardId {
if err := execution.DumpMainKeys(s.config.BlockGeneratorParams.MainKeysOutPath); err != nil {
return err
}
}

s.logger.Info().Msg("Generating zero-state...")

gen, err := execution.NewBlockGenerator(ctx, s.config.BlockGeneratorParams, s.db)
if err != nil {
return err
}
defer gen.Rollback()

_, err = gen.GenerateZeroState(s.config.ZeroState, s.config.ZeroStateConfig)
return err
block, err := gen.GenerateZeroState(s.config.ZeroState, s.config.ZeroStateConfig)
if err != nil {
return err
}

return PublishBlock(ctx, s.networkManager, s.config.ShardId, &types.BlockWithExtractedData{Block: block})
}

func validateRepliedBlock(
Expand Down
13 changes: 7 additions & 6 deletions nil/internal/execution/block_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import (
)

type BlockGeneratorParams struct {
ShardId types.ShardId
NShards uint32
TraceEVM bool
Timer common.Timer
GasBasePrice types.Value
GasPriceScale float64
ShardId types.ShardId
NShards uint32
TraceEVM bool
Timer common.Timer
GasBasePrice types.Value
GasPriceScale float64
MainKeysOutPath string
}

type Proposal struct {
Expand Down
14 changes: 7 additions & 7 deletions nil/services/nilservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,18 +557,18 @@ func createShards(
func createActiveCollator(shard types.ShardId, cfg *Config, collatorTickPeriod time.Duration, database db.DB, networkManager *network.Manager, txnPool txnpool.Pool) (*collate.Scheduler, error) {
collatorCfg := collate.Params{
BlockGeneratorParams: execution.BlockGeneratorParams{
ShardId: shard,
NShards: cfg.NShards,
TraceEVM: cfg.TraceEVM,
Timer: common.NewTimer(),
GasBasePrice: types.NewValueFromUint64(cfg.GasBasePrice),
GasPriceScale: cfg.GasPriceScale,
ShardId: shard,
NShards: cfg.NShards,
TraceEVM: cfg.TraceEVM,
Timer: common.NewTimer(),
GasBasePrice: types.NewValueFromUint64(cfg.GasBasePrice),
GasPriceScale: cfg.GasPriceScale,
MainKeysOutPath: cfg.MainKeysOutPath,
},
CollatorTickPeriod: collatorTickPeriod,
Timeout: collatorTickPeriod,
ZeroState: execution.DefaultZeroStateConfig,
ZeroStateConfig: cfg.ZeroState,
MainKeysOutPath: cfg.MainKeysOutPath,
Topology: collate.GetShardTopologyById(cfg.Topology),
}
if len(cfg.ZeroStateYaml) != 0 {
Expand Down

0 comments on commit 7ccd1e9

Please sign in to comment.