Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry connection on height mismatch #2474

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Changelog for NeoFS Node
- Double voting for validators on IR startup (#2365)
- Skip unexpected notary events on notary request parsing step (#2315)
- Session inactivity on object PUT request relay (#2460)
- Missing connection retries on IR node startup when the first configured mainnet RPC node is not in sync (#2474)

### Removed
- Deprecated `morph.rpc_endpoint` SN and `morph.endpoint.client` IR config sections (#2400)
Expand Down
9 changes: 7 additions & 2 deletions pkg/innerring/innerring.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,13 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<-
return nil, err
}

// create mainnet listener
server.mainnetListener, err = createListener(ctx, server.mainnetClient, mainnetChain)
// create mainnet listener, retry with a different node if current one is not up to date
for {
server.mainnetListener, err = createListener(ctx, server.mainnetClient, mainnetChain)
if !errors.Is(err, subscriber.ErrStaleNode) || !server.mainnetClient.SwitchRPC() {
break
}
}
if err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/morph/subscriber/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (s *subscriber) NotificationChannels() NotificationChannels {
}

var (
// ErrStaleNode is returned from [New] when StartFromBlock requirement
// specified in [Params] is not satisfied by the given node.
ErrStaleNode = errors.New("RPC node is not yet up to date")
carpawell marked this conversation as resolved.
Show resolved Hide resolved
errNilParams = errors.New("chain/subscriber: config was not provided to the constructor")

errNilLogger = errors.New("chain/subscriber: logger was not provided to the constructor")
Expand Down Expand Up @@ -332,8 +335,8 @@ func awaitHeight(cli *client.Client, startFrom uint32) error {
return fmt.Errorf("could not get block height: %w", err)
}

if height < startFrom {
return fmt.Errorf("RPC block counter %d didn't reach expected height %d", height, startFrom)
if height < startFrom+1 {
return fmt.Errorf("%w: expected %d height, got %d count", ErrStaleNode, startFrom, height)
}

return nil
Expand Down
Loading