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:
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)
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
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
......
......@@ -62,6 +62,7 @@ const (
optionNameFullNode = "full-node"
optionNamePostageContractAddress = "postage-stamp-address"
optionNamePriceOracleAddress = "price-oracle-address"
optionNameBlockTime = "block-time"
)
func init() {
......@@ -232,6 +233,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().String(optionNamePostageContractAddress, "", "postage stamp contract address")
cmd.Flags().String(optionNamePriceOracleAddress, "", "price oracle address")
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) {
......
......@@ -12,6 +12,8 @@ import (
"github.com/spf13/cobra"
)
const blocktime = 15
func (c *command) initDeployCmd() error {
cmd := &cobra.Command{
Use: "deploy",
......@@ -58,6 +60,7 @@ func (c *command) initDeployCmd() error {
stateStore,
swapEndpoint,
signer,
blocktime,
)
if err != nil {
return err
......
......@@ -151,6 +151,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
Transaction: c.config.GetString(optionNameTransactionHash),
PostageContractAddress: c.config.GetString(optionNamePostageContractAddress),
PriceOracleAddress: c.config.GetString(optionNamePriceOracleAddress),
BlockTime: c.config.GetUint64(optionNameBlockTime),
})
if err != nil {
return err
......
......@@ -25,7 +25,6 @@ import (
const (
maxDelay = 1 * time.Minute
pollingInterval = 15 * time.Second
cancellationDepth = 6
)
......@@ -37,6 +36,7 @@ func InitChain(
stateStore storage.StateStorer,
endpoint string,
signer crypto.Signer,
blocktime uint64,
) (*ethclient.Client, common.Address, int64, transaction.Monitor, transaction.Service, error) {
backend, err := ethclient.Dial(endpoint)
if err != nil {
......@@ -49,6 +49,7 @@ func InitChain(
return nil, common.Address{}, 0, nil, nil, fmt.Errorf("get chain id: %w", err)
}
pollingInterval := time.Duration(blocktime) * time.Second
overlayEthAddress, err := signer.EthereumAddress()
if err != nil {
return nil, common.Address{}, 0, nil, nil, fmt.Errorf("eth address: %w", err)
......
......@@ -131,6 +131,7 @@ type Options struct {
Transaction string
PostageContractAddress 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) {
......@@ -223,6 +224,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
stateStore,
o.SwapEndpoint,
signer,
o.BlockTime,
)
if err != nil {
return nil, fmt.Errorf("init chain: %w", err)
......@@ -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")
}
eventListener := listener.New(logger, swapBackend, postageContractAddress, priceOracleAddress)
eventListener := listener.New(logger, swapBackend, postageContractAddress, priceOracleAddress, o.BlockTime)
b.listenerCloser = eventListener
batchSvc = batchservice.New(batchStore, logger, eventListener)
......
......@@ -25,14 +25,13 @@ import (
)
const (
blockPage = 10000 // how many blocks to sync every time
tailSize = 4 // how many blocks to tail from the tip of the chain
blockPage = 5000 // how many blocks to sync every time we page
tailSize = 4 // how many blocks to tail from the tip of the chain
)
var (
chainUpdateInterval = 5 * time.Second
postageStampABI = parseABI(postageabi.PostageStampABIv0_1_0)
priceOracleABI = parseABI(postageabi.PriceOracleABIv0_1_0)
postageStampABI = parseABI(postageabi.PostageStampABIv0_1_0)
priceOracleABI = parseABI(postageabi.PriceOracleABIv0_1_0)
// batchCreatedTopic is the postage contract's batch created event topic
batchCreatedTopic = postageStampABI.Events["BatchCreated"].ID
// batchTopupTopic is the postage contract's batch topup event topic
......@@ -49,8 +48,9 @@ type BlockHeightContractFilterer interface {
}
type listener struct {
logger logging.Logger
ev BlockHeightContractFilterer
logger logging.Logger
ev BlockHeightContractFilterer
blockTime uint64
postageStampAddress common.Address
priceOracleAddress common.Address
......@@ -63,10 +63,12 @@ func New(
ev BlockHeightContractFilterer,
postageStampAddress,
priceOracleAddress common.Address,
blockTime uint64,
) postage.Listener {
return &listener{
logger: logger,
ev: ev,
logger: logger,
ev: ev,
blockTime: blockTime,
postageStampAddress: postageStampAddress,
priceOracleAddress: priceOracleAddress,
......@@ -149,6 +151,8 @@ func (l *listener) Listen(from uint64, updater postage.EventUpdater) <-chan stru
cancel()
}()
chainUpdateInterval := (time.Duration(l.blockTime) * time.Second) / 2
synced := make(chan struct{})
closeOnce := new(sync.Once)
paged := make(chan struct{}, 1)
......
......@@ -45,7 +45,7 @@ func TestListener(t *testing.T) {
c.toLog(),
),
)
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress)
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
listener.Listen(0, ev)
select {
......@@ -76,7 +76,7 @@ func TestListener(t *testing.T) {
topup.toLog(),
),
)
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress)
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
listener.Listen(0, ev)
select {
......@@ -107,7 +107,7 @@ func TestListener(t *testing.T) {
depthIncrease.toLog(),
),
)
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress)
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
listener.Listen(0, ev)
select {
......@@ -136,7 +136,7 @@ func TestListener(t *testing.T) {
priceUpdate.toLog(),
),
)
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress)
listener := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
listener.Listen(0, ev)
select {
......@@ -191,7 +191,7 @@ func TestListener(t *testing.T) {
),
WithBlockNumber(blockNumber),
)
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress)
l := listener.New(logger, mf, postageStampAddress, priceOracleAddress, 1)
l.Listen(0, ev)
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