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

Implement missing endpoints #6

Merged
merged 12 commits into from
Jan 30, 2024
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

## Unreleased changes
- Added support for GRPC V2 `GetWinningBakersEpoch` for getting a list of bakers that won the lottery in a particular historical epoch. Only available when querying a node with version at least 6.1.
- Added support for GRPC V2 `GetFirstBlockEpoch` for getting the block hash of the first finalized block in a specified epoch. Only available when querying a node with version at least 6.1.
- Added support for GRPC V2 `GetBakerEarliestWinTime` for getting the projected earliest time at which a particular baker will be required to bake a block. Only available when querying a node with version at least 6.1.
- Added support for GRPC V2 `GetBakerRewardPeriodInfo` for getting all the bakers in the reward period of a block. Only available when querying a node with version at least 6.1.
- Added support for GRPC V2 `GetBlockCertificates` for retrieving certificates for a block supporting ConcordiumBF, i.e. a node with at least version 6.1.
30 changes: 30 additions & 0 deletions v2/getbakerearliestwintime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package v2

import (
"context"

"github.com/Concordium/concordium-go-sdk/v2/pb"
)

// GetBakerEarliestWinTime retrieves the projected earliest time at which a particular baker will be required to bake a block.
//
// - If the baker is not a baker for the current reward period, this returns a timestamp at the start of the next reward period.
// - If the baker is a baker for the current reward period, the earliest win time is projected from the current round forwward,
// assuming that each round after the last finalixed round will take the minimum block time. (If blocks take longer, or timeouts occur,
// the actual time may be later, and the reported time in subsequent queries may reflect this.)
// - At the end of an epoch (or if the baker is not projected to bake before the end of the epoch)
// the earliest win time for a (current) baker will be projected as the start of the next epoch.
// This is because the seed for the leader election is updated at the epoch boundary,
// and so the winners cannot be predicted beyond that.
//
// Note that in some circumstances the returned timestamp can be in the past, especially at the end of an epoch.
//
// This endpoint is only supported for protocol version 6 and onwards.
func (c *Client) GetBakerEarliestWinTime(ctx context.Context, req *pb.BakerId) (_ *pb.Timestamp, err error) {
magnusbechwind marked this conversation as resolved.
Show resolved Hide resolved
timestamp, err := c.GrpcClient.GetBakerEarliestWinTime(ctx, req)
if err != nil {
return &pb.Timestamp{}, err
}

return timestamp, nil
}
19 changes: 19 additions & 0 deletions v2/getbakersrewardperiod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v2

import (
"context"

"github.com/Concordium/concordium-go-sdk/v2/pb"
)

// GetBakersRewardPeriod retrieves all bakers in the reward period of a block.
//
// This endpoint is only supported for protocol version 6 and onwards.
func (c *Client) GetBakersRewardPeriod(ctx context.Context, req isBlockHashInput) (_ pb.Queries_GetBakersRewardPeriodClient, err error) {
magnusbechwind marked this conversation as resolved.
Show resolved Hide resolved
stream, err := c.GrpcClient.GetBakersRewardPeriod(ctx, convertBlockHashInput(req))
if err != nil {
return nil, err
}

return stream, nil
}
20 changes: 20 additions & 0 deletions v2/getblockcertificates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v2

import (
"context"

"github.com/Concordium/concordium-go-sdk/v2/pb"
)

// GetBlockCertificates returns the quorum certificate, a timeout certificate (if present) and epoch finalization certificate (if present)
// for a non-genesis block.
//
// This endpoint is only supported for protocol version 6 and onwards.
func (c *Client) GetBlockCertificates(ctx context.Context, req isBlockHashInput) (_ *pb.BlockCertificates, err error) {
certificates, err := c.GrpcClient.GetBlockCertificates(ctx, convertBlockHashInput(req))
if err != nil {
return &pb.BlockCertificates{}, err
}

return certificates, nil
}
26 changes: 26 additions & 0 deletions v2/getfirstblockepoch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package v2

import (
"context"

"github.com/Concordium/concordium-go-sdk/v2/pb"
)

// GetFirstBlockEpoch retrieves the block hash of the first finalized block in a specified epoch.
//
// The following errors are possible:
// - `NOT_FOUND` if the query specifies an unknown block.
// - `UNAVAILABLE` if the query is for an epoch that is not finalized in the current genesis index, or is for a future genesis index.
// - `INVALID_ARGUMENT` if the query is for an epoch with no finalized blocks for a past genesis index.
// - `INVALID_ARGUMENT` if the input `EpochRequest` is malformed.
// - `UNIMPLEMENTED` if the endpoint is disabled on the node.
//
// This endpoint is only supported for protocol version 6 and onwards.
func (c *Client) GetFirstBlockEpoch(ctx context.Context, req isEpochRequest) (_ *pb.BlockHash, err error) {
magnusbechwind marked this conversation as resolved.
Show resolved Hide resolved
resp, err := c.GrpcClient.GetFirstBlockEpoch(ctx, convertEpochRequest(req))
if err != nil {
return nil, err
}

return resp, nil
}
31 changes: 31 additions & 0 deletions v2/getwinningbakersepoch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package v2

import (
"context"

"github.com/Concordium/concordium-go-sdk/v2/pb"
)

// GetWinningBakersEpoch retrieves the list of bakers that won the lottery in a particular historical epoch
// (i.e. the last finalized block is in a later epoch). This lists the winners for each round in the
// epoch, starting from the round after the last block in the previous epoch, running to
// the round before the first block in the next epoch. It also indicates if a block in each
// round was included in the finalized chain.
//
// The following error cases are possible:
// - `NOT_FOUND` if the query specifies an unknown block.
// - `UNAVAILABLE` if the query is for an epoch that is not finalized in the current genesis index, or is for a future genesis index.
// - `INVALID_ARGUMENT` if the query is for an epoch that is not finalized for a past genesis index.
// - `INVALID_ARGUMENT` if the query is for a genesis index at consensus version 0.
// - `INVALID_ARGUMENT` if the input `EpochRequest` is malformed.
// - `UNIMPLEMENTED` if the endpoint is disabled on the node.
//
// This endpoint is only supported for protocol version 6 and onwards.
func (c *Client) GetWinningBakersEpoch(ctx context.Context, req isEpochRequest) (_ pb.Queries_GetWinningBakersEpochClient, err error) {
magnusbechwind marked this conversation as resolved.
Show resolved Hide resolved
stream, err := c.GrpcClient.GetWinningBakersEpoch(ctx, convertEpochRequest(req))
if err != nil {
return nil, err
}

return stream, nil
}
98 changes: 49 additions & 49 deletions v2/pb/health.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions v2/pb/health.proto

This file was deleted.

10 changes: 5 additions & 5 deletions v2/pb/health_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading