Commit d3ef3e19 authored by acud's avatar acud Committed by GitHub

feat: add block-time cli flag (#1697)

parent 995af63f
...@@ -76,7 +76,7 @@ jobs: ...@@ -76,7 +76,7 @@ jobs:
run: ./beekeeper check settlements --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}" --upload-node-count "${REPLICA}" -t 1000000000000 run: ./beekeeper check settlements --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}" --upload-node-count "${REPLICA}" -t 1000000000000
- name: Test pushsync (chunks) - name: Test pushsync (chunks)
id: pushsync-chunks-1 id: pushsync-chunks-1
run: ./beekeeper check pushsync --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}" --upload-node-count "${REPLICA}" --chunks-per-node 3 --upload-chunks run: ./beekeeper check pushsync --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}" --upload-node-count "${REPLICA}" --chunks-per-node 3 --upload-chunks --retry-delay 10s
- name: Test retrieval - name: Test retrieval
id: retrieval-1 id: retrieval-1
run: ./beekeeper check retrieval --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}" --upload-node-count "${REPLICA}" --chunks-per-node 3 run: ./beekeeper check retrieval --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}" --upload-node-count "${REPLICA}" --chunks-per-node 3
......
...@@ -62,6 +62,7 @@ const ( ...@@ -62,6 +62,7 @@ const (
optionNameFullNode = "full-node" optionNameFullNode = "full-node"
optionNamePostageContractAddress = "postage-stamp-address" optionNamePostageContractAddress = "postage-stamp-address"
optionNamePriceOracleAddress = "price-oracle-address" optionNamePriceOracleAddress = "price-oracle-address"
optionNameBlockTime = "block-time"
) )
func init() { func init() {
...@@ -232,6 +233,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) { ...@@ -232,6 +233,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().String(optionNamePostageContractAddress, "", "postage stamp contract address") cmd.Flags().String(optionNamePostageContractAddress, "", "postage stamp contract address")
cmd.Flags().String(optionNamePriceOracleAddress, "", "price oracle address") cmd.Flags().String(optionNamePriceOracleAddress, "", "price oracle address")
cmd.Flags().String(optionNameTransactionHash, "", "proof-of-identity transaction hash") cmd.Flags().String(optionNameTransactionHash, "", "proof-of-identity transaction hash")
cmd.Flags().Uint64(optionNameBlockTime, 15, "chain block time")
} }
func newLogger(cmd *cobra.Command, verbosity string) (logging.Logger, error) { func newLogger(cmd *cobra.Command, verbosity string) (logging.Logger, error) {
......
...@@ -12,6 +12,8 @@ import ( ...@@ -12,6 +12,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
const blocktime = 15
func (c *command) initDeployCmd() error { func (c *command) initDeployCmd() error {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "deploy", Use: "deploy",
...@@ -58,6 +60,7 @@ func (c *command) initDeployCmd() error { ...@@ -58,6 +60,7 @@ func (c *command) initDeployCmd() error {
stateStore, stateStore,
swapEndpoint, swapEndpoint,
signer, signer,
blocktime,
) )
if err != nil { if err != nil {
return err return err
......
...@@ -151,6 +151,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz ...@@ -151,6 +151,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
Transaction: c.config.GetString(optionNameTransactionHash), Transaction: c.config.GetString(optionNameTransactionHash),
PostageContractAddress: c.config.GetString(optionNamePostageContractAddress), PostageContractAddress: c.config.GetString(optionNamePostageContractAddress),
PriceOracleAddress: c.config.GetString(optionNamePriceOracleAddress), PriceOracleAddress: c.config.GetString(optionNamePriceOracleAddress),
BlockTime: c.config.GetUint64(optionNameBlockTime),
}) })
if err != nil { if err != nil {
return err return err
......
...@@ -25,7 +25,6 @@ import ( ...@@ -25,7 +25,6 @@ import (
const ( const (
maxDelay = 1 * time.Minute maxDelay = 1 * time.Minute
pollingInterval = 15 * time.Second
cancellationDepth = 6 cancellationDepth = 6
) )
...@@ -37,6 +36,7 @@ func InitChain( ...@@ -37,6 +36,7 @@ func InitChain(
stateStore storage.StateStorer, stateStore storage.StateStorer,
endpoint string, endpoint string,
signer crypto.Signer, signer crypto.Signer,
blocktime uint64,
) (*ethclient.Client, common.Address, int64, transaction.Monitor, transaction.Service, error) { ) (*ethclient.Client, common.Address, int64, transaction.Monitor, transaction.Service, error) {
backend, err := ethclient.Dial(endpoint) backend, err := ethclient.Dial(endpoint)
if err != nil { if err != nil {
...@@ -49,6 +49,7 @@ func InitChain( ...@@ -49,6 +49,7 @@ func InitChain(
return nil, common.Address{}, 0, nil, nil, fmt.Errorf("get chain id: %w", err) return nil, common.Address{}, 0, nil, nil, fmt.Errorf("get chain id: %w", err)
} }
pollingInterval := time.Duration(blocktime) * time.Second
overlayEthAddress, err := signer.EthereumAddress() overlayEthAddress, err := signer.EthereumAddress()
if err != nil { if err != nil {
return nil, common.Address{}, 0, nil, nil, fmt.Errorf("eth address: %w", err) return nil, common.Address{}, 0, nil, nil, fmt.Errorf("eth address: %w", err)
......
...@@ -131,6 +131,7 @@ type Options struct { ...@@ -131,6 +131,7 @@ type Options struct {
Transaction string Transaction string
PostageContractAddress string PostageContractAddress string
PriceOracleAddress string PriceOracleAddress string
BlockTime uint64
} }
func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, signer crypto.Signer, networkID uint64, logger logging.Logger, libp2pPrivateKey, pssPrivateKey *ecdsa.PrivateKey, o Options) (b *Bee, err error) { func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, signer crypto.Signer, networkID uint64, logger logging.Logger, libp2pPrivateKey, pssPrivateKey *ecdsa.PrivateKey, o Options) (b *Bee, err error) {
...@@ -223,6 +224,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -223,6 +224,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
stateStore, stateStore,
o.SwapEndpoint, o.SwapEndpoint,
signer, signer,
o.BlockTime,
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("init chain: %w", err) return nil, fmt.Errorf("init chain: %w", err)
...@@ -351,7 +353,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -351,7 +353,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
return nil, errors.New("no known postage stamp addresses for this network") return nil, errors.New("no known postage stamp addresses for this network")
} }
eventListener := listener.New(logger, swapBackend, postageContractAddress, priceOracleAddress) eventListener := listener.New(logger, swapBackend, postageContractAddress, priceOracleAddress, o.BlockTime)
b.listenerCloser = eventListener b.listenerCloser = eventListener
batchSvc = batchservice.New(batchStore, logger, eventListener) batchSvc = batchservice.New(batchStore, logger, eventListener)
......
...@@ -25,14 +25,13 @@ import ( ...@@ -25,14 +25,13 @@ import (
) )
const ( const (
blockPage = 10000 // how many blocks to sync every time blockPage = 5000 // how many blocks to sync every time we page
tailSize = 4 // how many blocks to tail from the tip of the chain tailSize = 4 // how many blocks to tail from the tip of the chain
) )
var ( var (
chainUpdateInterval = 5 * time.Second postageStampABI = parseABI(postageabi.PostageStampABIv0_1_0)
postageStampABI = parseABI(postageabi.PostageStampABIv0_1_0) priceOracleABI = parseABI(postageabi.PriceOracleABIv0_1_0)
priceOracleABI = parseABI(postageabi.PriceOracleABIv0_1_0)
// batchCreatedTopic is the postage contract's batch created event topic // batchCreatedTopic is the postage contract's batch created event topic
batchCreatedTopic = postageStampABI.Events["BatchCreated"].ID batchCreatedTopic = postageStampABI.Events["BatchCreated"].ID
// batchTopupTopic is the postage contract's batch topup event topic // batchTopupTopic is the postage contract's batch topup event topic
...@@ -49,8 +48,9 @@ type BlockHeightContractFilterer interface { ...@@ -49,8 +48,9 @@ type BlockHeightContractFilterer interface {
} }
type listener struct { type listener struct {
logger logging.Logger logger logging.Logger
ev BlockHeightContractFilterer ev BlockHeightContractFilterer
blockTime uint64
postageStampAddress common.Address postageStampAddress common.Address
priceOracleAddress common.Address priceOracleAddress common.Address
...@@ -63,10 +63,12 @@ func New( ...@@ -63,10 +63,12 @@ func New(
ev BlockHeightContractFilterer, ev BlockHeightContractFilterer,
postageStampAddress, postageStampAddress,
priceOracleAddress common.Address, priceOracleAddress common.Address,
blockTime uint64,
) postage.Listener { ) postage.Listener {
return &listener{ return &listener{
logger: logger, logger: logger,
ev: ev, ev: ev,
blockTime: blockTime,
postageStampAddress: postageStampAddress, postageStampAddress: postageStampAddress,
priceOracleAddress: priceOracleAddress, priceOracleAddress: priceOracleAddress,
...@@ -149,6 +151,8 @@ func (l *listener) Listen(from uint64, updater postage.EventUpdater) <-chan stru ...@@ -149,6 +151,8 @@ func (l *listener) Listen(from uint64, updater postage.EventUpdater) <-chan stru
cancel() cancel()
}() }()
chainUpdateInterval := (time.Duration(l.blockTime) * time.Second) / 2
synced := make(chan struct{}) synced := make(chan struct{})
closeOnce := new(sync.Once) closeOnce := new(sync.Once)
paged := make(chan struct{}, 1) paged := make(chan struct{}, 1)
......
...@@ -45,7 +45,7 @@ func TestListener(t *testing.T) { ...@@ -45,7 +45,7 @@ func TestListener(t *testing.T) {
c.toLog(), c.toLog(),
), ),
) )
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress) listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
listener.Listen(0, ev) listener.Listen(0, ev)
select { select {
...@@ -76,7 +76,7 @@ func TestListener(t *testing.T) { ...@@ -76,7 +76,7 @@ func TestListener(t *testing.T) {
topup.toLog(), topup.toLog(),
), ),
) )
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress) listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
listener.Listen(0, ev) listener.Listen(0, ev)
select { select {
...@@ -107,7 +107,7 @@ func TestListener(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestListener(t *testing.T) {
depthIncrease.toLog(), depthIncrease.toLog(),
), ),
) )
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress) listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
listener.Listen(0, ev) listener.Listen(0, ev)
select { select {
...@@ -136,7 +136,7 @@ func TestListener(t *testing.T) { ...@@ -136,7 +136,7 @@ func TestListener(t *testing.T) {
priceUpdate.toLog(), priceUpdate.toLog(),
), ),
) )
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress) listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
listener.Listen(0, ev) listener.Listen(0, ev)
select { select {
...@@ -191,7 +191,7 @@ func TestListener(t *testing.T) { ...@@ -191,7 +191,7 @@ func TestListener(t *testing.T) {
), ),
WithBlockNumber(blockNumber), WithBlockNumber(blockNumber),
) )
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress) l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
l.Listen(0, ev) l.Listen(0, ev)
select { select {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment