Skip to content

Commit

Permalink
move DefaultBlockTime to plumbin/clock
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Jun 6, 2019
1 parent 78ecec7 commit bc08932
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions commands/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"github.com/pkg/errors"

"github.com/filecoin-project/go-filecoin/config"
"github.com/filecoin-project/go-filecoin/mining"
"github.com/filecoin-project/go-filecoin/node"
"github.com/filecoin-project/go-filecoin/paths"
"github.com/filecoin-project/go-filecoin/plumbing/clock"
"github.com/filecoin-project/go-filecoin/repo"
)

Expand All @@ -38,7 +38,7 @@ var daemonCmd = &cmds.Command{
cmdkit.BoolOption(OfflineMode, "start the node without networking"),
cmdkit.BoolOption(ELStdout),
cmdkit.BoolOption(IsRelay, "advertise and allow filecoin network traffic to be relayed through this node"),
cmdkit.StringOption(BlockTime, "time a node waits before trying to mine the next block").WithDefault(mining.DefaultBlockTime.String()),
cmdkit.StringOption(BlockTime, "time a node waits before trying to mine the next block").WithDefault(clock.DefaultBlockTime.String()),
},
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
return daemonRun(req, re, env)
Expand Down Expand Up @@ -95,7 +95,7 @@ func daemonRun(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment)
if err != nil {
return errors.Wrap(err, "Bad block time passed")
}
opts = append(opts, node.BlockClock(blockTime))
opts = append(opts, node.BlockClock(clock.NewConfiguredBlockClock(blockTime)))

fcn, err := node.New(req.Context, opts...)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions mining/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import (

var log = logging.Logger("mining")

// DefaultBlockTime is the estimated proving period time.
// We define this so that we can fake mining in the current incomplete system.
const DefaultBlockTime = 30 * time.Second

// Output is the result of a single mining run. It has either a new
// block or an error, mimicing the golang (retVal, error) pattern.
// If a mining run's context is canceled there is no output.
Expand Down
6 changes: 3 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ func IsRelay() ConfigOpt {
}

// BlockClock sets the clock.
func BlockClock(blockTime time.Duration) ConfigOpt {
func BlockClock(clk clock.BlockClock) ConfigOpt {
return func(c *Config) error {
c.Clock = clock.NewDefaultBlockClock(blockTime)
c.Clock = clk
return nil
}
}
Expand Down Expand Up @@ -381,7 +381,7 @@ func (nc *Config) Build(ctx context.Context) (*Node, error) {
// DO NOT MERGE this code smells like poo, this smell exists elsewhere,
// should have defaults set on it _before_ we get here?
if nc.Clock == nil {
nc.Clock = clock.NewDefaultBlockClock(mining.DefaultBlockTime)
nc.Clock = clock.NewDefaultBlockClock()
}

// setup block validation
Expand Down
3 changes: 2 additions & 1 deletion node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/filecoin-project/go-filecoin/consensus"
"github.com/filecoin-project/go-filecoin/mining"
"github.com/filecoin-project/go-filecoin/node"
"github.com/filecoin-project/go-filecoin/plumbing/clock"
"github.com/filecoin-project/go-filecoin/proofs"
"github.com/filecoin-project/go-filecoin/protocol/storage"
"github.com/filecoin-project/go-filecoin/repo"
Expand Down Expand Up @@ -198,7 +199,7 @@ func TestNodeConfig(t *testing.T) {
configOptions := []node.ConfigOpt{
repoConfig(),
node.VerifierConfigOption(verifier),
node.BlockClock(time.Duration(configBlockTime)),
node.BlockClock(clock.NewConfiguredBlockClock(time.Duration(configBlockTime))),
}

initOpts := []node.InitOpt{node.AutoSealIntervalSecondsOpt(120)}
Expand Down
19 changes: 16 additions & 3 deletions plumbing/clock/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"time"
)

// DefaultBlockTime is the estimated proving period time.
// We define this so that we can fake mining in the current incomplete system.
const DefaultBlockTime = 30 * time.Second

// BlockClock defines an interface for fetching the block time.
type BlockClock interface {
BlockTime() time.Duration
Expand All @@ -16,10 +20,19 @@ type DefaultBlockClock struct {
}

// NewDefaultBlockClock returns a DefaultBlockClock. It can be used to
// get the value of block time.
func NewDefaultBlockClock(t time.Duration) *DefaultBlockClock {
// get the value of block time. NewDefaultBlockClock uses DefaltBlockTime
// as the block time.
func NewDefaultBlockClock() *DefaultBlockClock {
return &DefaultBlockClock{
blockTime: DefaultBlockTime,
}
}

// NewConfiguredBlockClock returns a DefaultBlockClock with the provided
// blockTime.
func NewConfiguredBlockClock(blockTime time.Duration) *DefaultBlockClock {
return &DefaultBlockClock{
blockTime: t,
blockTime: blockTime,
}
}

Expand Down
4 changes: 2 additions & 2 deletions tools/fast/series/ctx_sleep_delay.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/filecoin-project/go-filecoin/mining"
"github.com/filecoin-project/go-filecoin/plumbing/clock"
)

type ctxSleepDelayKey struct{}
Expand All @@ -14,7 +14,7 @@ var (
sleepDelayKey = ctxSleepDelayKey{}

// Default delay
defaultSleepDelay = mining.DefaultBlockTime
defaultSleepDelay = clock.DefaultBlockTime
)

// SetCtxSleepDelay returns a context with `d` set in the context. To sleep with
Expand Down

0 comments on commit bc08932

Please sign in to comment.