Commit ea178d68 authored by Ralph Pichler's avatar Ralph Pichler Committed by GitHub

fix: start syncing at a later block (#1745)

parent dbfd7452
...@@ -343,8 +343,9 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -343,8 +343,9 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
batchSvc postage.EventUpdater batchSvc postage.EventUpdater
) )
var postageSyncStart uint64 = 0
if !o.Standalone { if !o.Standalone {
postageContractAddress, priceOracleAddress, found := listener.DiscoverAddresses(chainID) postageContractAddress, priceOracleAddress, startBlock, found := listener.DiscoverAddresses(chainID)
if o.PostageContractAddress != "" { if o.PostageContractAddress != "" {
if !common.IsHexAddress(o.PostageContractAddress) { if !common.IsHexAddress(o.PostageContractAddress) {
return nil, errors.New("malformed postage stamp address") return nil, errors.New("malformed postage stamp address")
...@@ -360,6 +361,9 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -360,6 +361,9 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
if (o.PostageContractAddress == "" || o.PriceOracleAddress == "") && !found { if (o.PostageContractAddress == "" || o.PriceOracleAddress == "") && !found {
return nil, errors.New("no known postage stamp addresses for this network") return nil, errors.New("no known postage stamp addresses for this network")
} }
if found {
postageSyncStart = startBlock
}
eventListener := listener.New(logger, swapBackend, postageContractAddress, priceOracleAddress, o.BlockTime) eventListener := listener.New(logger, swapBackend, postageContractAddress, priceOracleAddress, o.BlockTime)
b.listenerCloser = eventListener b.listenerCloser = eventListener
...@@ -438,7 +442,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -438,7 +442,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
batchStore.SetRadiusSetter(kad) batchStore.SetRadiusSetter(kad)
if batchSvc != nil { if batchSvc != nil {
syncedChan := batchSvc.Start() syncedChan := batchSvc.Start(postageSyncStart)
// wait for the postage contract listener to sync // wait for the postage contract listener to sync
logger.Info("waiting to sync postage contract data, this may take a while... more info available in Debug loglevel") logger.Info("waiting to sync postage contract data, this may take a while... more info available in Debug loglevel")
......
...@@ -108,7 +108,10 @@ func (svc *batchService) UpdateBlockNumber(blockNumber uint64) error { ...@@ -108,7 +108,10 @@ func (svc *batchService) UpdateBlockNumber(blockNumber uint64) error {
return nil return nil
} }
func (svc *batchService) Start() <-chan struct{} { func (svc *batchService) Start(startBlock uint64) <-chan struct{} {
cs := svc.storer.GetChainState() cs := svc.storer.GetChainState()
return svc.listener.Listen(cs.Block+1, svc) if cs.Block > startBlock {
startBlock = cs.Block
}
return svc.listener.Listen(startBlock+1, svc)
} }
...@@ -17,7 +17,7 @@ type EventUpdater interface { ...@@ -17,7 +17,7 @@ type EventUpdater interface {
UpdateDepth(id []byte, depth uint8, normalisedBalance *big.Int) error UpdateDepth(id []byte, depth uint8, normalisedBalance *big.Int) error
UpdatePrice(price *big.Int) error UpdatePrice(price *big.Int) error
UpdateBlockNumber(blockNumber uint64) error UpdateBlockNumber(blockNumber uint64) error
Start() <-chan struct{} Start(startBlock uint64) <-chan struct{}
} }
// Storer represents the persistence layer for batches on the current (highest // Storer represents the persistence layer for batches on the current (highest
......
...@@ -278,11 +278,17 @@ type priceUpdateEvent struct { ...@@ -278,11 +278,17 @@ type priceUpdateEvent struct {
Price *big.Int Price *big.Int
} }
var (
GoerliPostageStampContractAddress = common.HexToAddress("0xF7a041E7e2B79ccA1975852Eb6D4c6cE52986b4a")
GoerliPriceOracleContractAddress = common.HexToAddress("0x1044534090de6f4014ece6d036C699130Bd5Df43")
GoerliStartBlock = uint64(4247101)
)
// DiscoverAddresses returns the canonical contracts for this chainID // DiscoverAddresses returns the canonical contracts for this chainID
func DiscoverAddresses(chainID int64) (postageStamp, priceOracle common.Address, found bool) { func DiscoverAddresses(chainID int64) (postageStamp, priceOracle common.Address, startBlock uint64, found bool) {
if chainID == 5 { if chainID == 5 {
// goerli // goerli
return common.HexToAddress("0xF7a041E7e2B79ccA1975852Eb6D4c6cE52986b4a"), common.HexToAddress("0x1044534090de6f4014ece6d036C699130Bd5Df43"), true return GoerliPostageStampContractAddress, GoerliPriceOracleContractAddress, GoerliStartBlock, true
} }
return common.Address{}, common.Address{}, false return common.Address{}, common.Address{}, 0, false
} }
...@@ -279,7 +279,7 @@ func (u *updater) UpdateBlockNumber(blockNumber uint64) error { ...@@ -279,7 +279,7 @@ func (u *updater) UpdateBlockNumber(blockNumber uint64) error {
return nil return nil
} }
func (u *updater) Start() <-chan struct{} { return nil } func (u *updater) Start(_ uint64) <-chan struct{} { return nil }
type mockFilterer struct { type mockFilterer struct {
filterLogEvents []types.Log filterLogEvents []types.Log
......
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