Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Relayer reliability improvements (paritytech#349)
Browse files Browse the repository at this point in the history
* Many relayer fixes

* Fixes for E2E tests

* timeout better on startup

* Improve reliability of readme instructions

Co-authored-by: Aidan Musnitzky <[email protected]>
  • Loading branch information
vgeddes and musnit authored Apr 20, 2021
1 parent ce403c9 commit 5278832
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 114 deletions.
7 changes: 4 additions & 3 deletions ethereum/contracts/test/TestToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import "../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract TestToken is ERC20 {
constructor(
uint256 initialSupply,
string memory _name,
string memory _symbol
) ERC20(_name, _symbol) {
_mint(msg.sender, initialSupply);
) ERC20(_name, _symbol) { }

function mint(uint256 _amount) public {
_mint(msg.sender, _amount);
}
}
9 changes: 8 additions & 1 deletion ethereum/migrations/2_next.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = function (deployer, network, accounts) {
},
);

await deployer.deploy(TestToken, 100000000, "Test Token", "TEST");
const token = await deployer.deploy(TestToken, "Test Token", "TEST");

// Deploy ERC1820 Registry for our E2E stack.
if (network === 'e2e_test') {
Expand Down Expand Up @@ -126,6 +126,13 @@ module.exports = function (deployer, network, accounts) {
);
}

await token.mint("10000", {
from: accounts[0],
});
await token.mint("10000", {
from: accounts[1],
});

// Link MerkleProof library to ValidatorRegistry
await deployer.deploy(MerkleProof);
deployer.link(MerkleProof, [ValidatorRegistry]);
Expand Down
45 changes: 27 additions & 18 deletions relayer/chain/ethereum/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,17 @@ func (li *Listener) Start(cxt context.Context, eg *errgroup.Group, initBlockHeig
}
li.blockWaitPeriod = blockWaitPeriod.Uint64()
eg.Go(func() error {
return li.pollEventsAndHeaders(cxt, initBlockHeight, descendantsUntilFinal, hcs)
err := li.pollEventsAndHeaders(cxt, initBlockHeight, descendantsUntilFinal, hcs)
if li.messages != nil {
close(li.messages)
}
close(li.headers)
return err
})

return nil
}

func (li *Listener) onDone(ctx context.Context) error {
li.log.Info("Shutting down listener...")
if li.messages != nil {
close(li.messages)
}
close(li.headers)
return ctx.Err()
}

func (li *Listener) pollEventsAndHeaders(
ctx context.Context,
initBlockHeight uint64,
Expand All @@ -138,11 +134,16 @@ func (li *Listener) pollEventsAndHeaders(
for {
select {
case <-ctx.Done():
return li.onDone(ctx)
li.log.Info("Shutting down listener...")
return ctx.Err()
case <-headerCtx.Done():
return li.onDone(ctx)
li.log.Info("Shutting down listener...")
return ctx.Err()
case gethheader := <-headers:
li.forwardHeader(hcs, gethheader)
err := li.forwardHeader(hcs, gethheader)
if err != nil {
return err
}

if li.messages == nil {
li.log.Info("Not polling events since channel is nil")
Expand All @@ -161,12 +162,14 @@ func (li *Listener) pollEventsAndHeaders(
basicEvents, err := li.queryBasicEvents(li.basicOutboundChannel, &filterOptions)
if err != nil {
li.log.WithError(err).Error("Failure fetching event logs")
return err
}
events = append(events, basicEvents...)

incentivizedEvents, err := li.queryIncentivizedEvents(li.incentivizedOutboundChannel, &filterOptions)
if err != nil {
li.log.WithError(err).Error("Failure fetching event logs")
return err
}
events = append(events, incentivizedEvents...)

Expand All @@ -179,6 +182,7 @@ func (li *Listener) pollEventsAndHeaders(
contractEvents, err := li.queryLightClientEvents(ctx, blockNumber, &blockNumber)
if err != nil {
li.log.WithError(err).Error("Failure fetching event logs")
return err
}
lightClientBridgeEvents = append(lightClientBridgeEvents, contractEvents...)

Expand Down Expand Up @@ -254,7 +258,7 @@ func (li *Listener) queryIncentivizedEvents(contract *outbound.IncentivizedOutbo
return events, nil
}

func (li *Listener) forwardEvents(ctx context.Context, hcs *HeaderCacheState, events []*etypes.Log) {
func (li *Listener) forwardEvents(ctx context.Context, hcs *HeaderCacheState, events []*etypes.Log) error {
messages := make([]chain.Message, len(events))

for i, event := range events {
Expand All @@ -265,7 +269,7 @@ func (li *Listener) forwardEvents(ctx context.Context, hcs *HeaderCacheState, ev
"blockNumber": event.BlockNumber,
"txHash": event.TxHash.Hex(),
}).WithError(err).Error("Failed to get receipt trie for event")
return
return err
}

msg, err := MakeMessageFromEvent(li.mapping, event, receiptTrie, li.log)
Expand All @@ -276,7 +280,7 @@ func (li *Listener) forwardEvents(ctx context.Context, hcs *HeaderCacheState, ev
"blockNumber": event.BlockNumber,
"txHash": event.TxHash.Hex(),
}).WithError(err).Error("Failed to generate message from ethereum event")
return
return err
}

messages[i] = msg
Expand All @@ -288,16 +292,18 @@ func (li *Listener) forwardEvents(ctx context.Context, hcs *HeaderCacheState, ev
li.messages <- messages[start : i+1]
}
}

return nil
}

func (li *Listener) forwardHeader(hcs *HeaderCacheState, gethheader *gethTypes.Header) {
func (li *Listener) forwardHeader(hcs *HeaderCacheState, gethheader *gethTypes.Header) error {
cache, err := hcs.GetEthashproofCache(gethheader.Number.Uint64())
if err != nil {
li.log.WithFields(logrus.Fields{
"blockHash": gethheader.Hash().Hex(),
"blockNumber": gethheader.Number,
}).WithError(err).Error("Failed to get ethashproof cache for header")
return
return err
}

header, err := MakeHeaderFromEthHeader(gethheader, cache, li.log)
Expand All @@ -306,9 +312,12 @@ func (li *Listener) forwardHeader(hcs *HeaderCacheState, gethheader *gethTypes.H
"blockHash": gethheader.Hash().Hex(),
"blockNumber": gethheader.Number,
}).WithError(err).Error("Failed to generate header from ethereum header")
return err
} else {
li.headers <- *header
}

return nil
}

// queryLightClientEvents queries ContractInitialVerificationSuccessful events from the LightClientBridge contract
Expand Down
Loading

0 comments on commit 5278832

Please sign in to comment.