Skip to content

Commit

Permalink
Add new types
Browse files Browse the repository at this point in the history
  • Loading branch information
mikiquantum committed Dec 15, 2020
1 parent 58034cb commit b35bdd6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions chains/substrate/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ var ErrBlockNotReady = errors.New("required result to be 32 bytes, but got 0")
// Polling begins at the block defined in `l.startBlock`. Failed attempts to fetch the latest block or parse
// a block will be retried up to BlockRetryLimit times before returning with an error.
func (l *listener) pollBlocks() error {
l.log.Info("Polling Blocks...")
var currentBlock = l.startBlock
var retry = BlockRetryLimit
for {
select {
case <-l.stop:
return errors.New("terminated")
return errors.New("polling terminated")
default:
// No more retries, goto next block
if retry == 0 {
Expand Down Expand Up @@ -137,7 +138,7 @@ func (l *listener) pollBlocks() error {

// Sleep if the block we want comes after the most recently finalized block
if currentBlock > uint64(finalizedHeader.Number) {
l.log.Trace("Block not yet finalized", "target", currentBlock, "latest", finalizedHeader.Number)
l.log.Debug("Block not yet finalized", "target", currentBlock, "latest", finalizedHeader.Number)
time.Sleep(BlockRetryInterval)
continue
}
Expand All @@ -154,6 +155,8 @@ func (l *listener) pollBlocks() error {
continue
}

l.log.Debug("Querying block for deposit events", "target", currentBlock)

err = l.processEvents(hash)
if err != nil {
l.log.Error("Failed to process events in block", "block", currentBlock, "err", err)
Expand Down Expand Up @@ -182,7 +185,7 @@ func (l *listener) pollBlocks() error {

// processEvents fetches a block and parses out the events, calling Listener.handleEvents()
func (l *listener) processEvents(hash types.Hash) error {
l.log.Trace("Fetching block for events", "hash", hash.Hex())
l.log.Trace("Fetching events for block", "hash", hash.Hex())
meta := l.conn.getMetadata()
key, err := types.CreateStorageKey(&meta, "System", "Events", nil, nil)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/ChainSafe/chainbridge-utils v1.0.6
github.com/ChainSafe/log15 v1.0.0
github.com/aristanetworks/goarista v0.0.0-20200609010056-95bcf8053598 // indirect
github.com/centrifuge/go-substrate-rpc-client v2.0.0-rc6-0+incompatible
github.com/centrifuge/go-substrate-rpc-client v2.0.0-rc6.1+incompatible
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/ethereum/go-ethereum v1.9.17
github.com/gorilla/websocket v1.4.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.3+incompatible h1:d8h
github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.3+incompatible/go.mod h1:GBMLH8MQs5g4FcrytcMm9uRgBnTL1LIkNTue6lUPhZU=
github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.5+incompatible h1:QzFk38HaqnzjQ6DHra5WxcTf+KxbB0Hitg+72LEPVJI=
github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.5+incompatible/go.mod h1:GBMLH8MQs5g4FcrytcMm9uRgBnTL1LIkNTue6lUPhZU=
github.com/centrifuge/go-substrate-rpc-client v2.0.0-rc6.1+incompatible h1:HtNfFBeCH+Qys2XtWX1WCiD/X8oCXER8t4jcB8szR7w=
github.com/centrifuge/go-substrate-rpc-client v2.0.0-rc6.1+incompatible/go.mod h1:GBMLH8MQs5g4FcrytcMm9uRgBnTL1LIkNTue6lUPhZU=
github.com/centrifuge/go-substrate-rpc-client v2.0.0-rc6-0+incompatible h1:+H/LOoOMiAlww9xayOEAxa4mF6Tp+AgzzJDE9pQ37D8=
github.com/centrifuge/go-substrate-rpc-client v2.0.0-rc6-0+incompatible/go.mod h1:GBMLH8MQs5g4FcrytcMm9uRgBnTL1LIkNTue6lUPhZU=
github.com/centrifuge/go-substrate-rpc-client v2.0.0+incompatible h1:FvPewruOgelqA/DVBdX7/Q6znUGGQ+g0ciG5tA2Fk98=
Expand Down

0 comments on commit b35bdd6

Please sign in to comment.