Skip to content

Commit

Permalink
Merge pull request #263 from onflow/gregor/height-boundary
Browse files Browse the repository at this point in the history
Cross-spork client checks for boundaries
  • Loading branch information
sideninja authored May 27, 2024
2 parents bab9451 + 20173a8 commit aa84d6c
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 185 deletions.
2 changes: 1 addition & 1 deletion bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func startIngestion(
func startServer(
ctx context.Context,
cfg *config.Config,
client access.Client,
client *requester.CrossSporkClient,
blocks storage.BlockIndexer,
transactions storage.TransactionIndexer,
receipts storage.ReceiptIndexer,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/onflow/cadence v1.0.0-preview.29
github.com/onflow/flow-go v0.35.5-0.20240517202625-55f862b45dfd
github.com/onflow/flow-go-sdk v1.0.0-preview.30
github.com/onflow/flow-go-sdk v1.0.0-preview.30.0.20240523120036-f9d51677b347
github.com/onflow/go-ethereum v1.13.4
github.com/rs/cors v1.8.0
github.com/rs/zerolog v1.31.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo=
github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM=
github.com/aws/aws-sdk-go-v2 v1.23.1/go.mod h1:i1XDttT4rnf6vxc9AuskLc6s7XBee8rlLilKlc03uAA=
github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA=
github.com/aws/aws-sdk-go-v2 v1.27.0 h1:7bZWKoXhzI+mMR/HjdMx8ZCC5+6fY0lS5tr0bbgiLlo=
github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y=
github.com/aws/aws-sdk-go-v2/config v1.18.45/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE=
github.com/aws/aws-sdk-go-v2/config v1.25.5/go.mod h1:Bf4gDvy4ZcFIK0rqDu1wp9wrubNba2DojiPB2rt6nvI=
Expand All @@ -1024,7 +1024,7 @@ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1x
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2/go.mod h1:45MfaXZ0cNbeuT0KQ1XJylq8A6+OpVV2E5kvY/Kq+u8=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.4/go.mod h1:aYCGNjyUCUelhofxlZyj63srdxWUSsBSGg5l6MCuXuE=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 h1:ogRAwT1/gxJBcSWDMZlgyFUM962F51A5CRhDLbxLdmo=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.9 h1:Wx0rlZoEJR7JwlSZcHnEa7CNjrSIyVxMFWGAaXy4fJY=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.7.0 h1:HWsM0YQWX76V6MOp07YuTYacm8k7h69ObJuw7Nck+og=
github.com/aws/aws-sdk-go-v2/service/kms v1.26.3/go.mod h1:N3++/sLV97B8Zliz7KRqNcojOX7iMBZWKiuit5FKtH0=
github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1/go.mod h1:rLiOUrPLW/Er5kRcQ7NkwbjlijluLsrIbu/iyl35RO4=
Expand Down Expand Up @@ -1885,8 +1885,8 @@ github.com/onflow/flow-ft/lib/go/templates v1.0.0/go.mod h1:uQ8XFqmMK2jxyBSVrmyu
github.com/onflow/flow-go v0.35.5-0.20240517202625-55f862b45dfd h1:bSoQMARSC4dk6sQPv6SRkV7QvovKoNksTnydK9e5hL4=
github.com/onflow/flow-go v0.35.5-0.20240517202625-55f862b45dfd/go.mod h1:5ysH9wggXlvJqbALEBZc2uNx6DIE+QsBoocuM8bSGC0=
github.com/onflow/flow-go-sdk v1.0.0-M1/go.mod h1:TDW0MNuCs4SvqYRUzkbRnRmHQL1h4X8wURsCw9P9beo=
github.com/onflow/flow-go-sdk v1.0.0-preview.30 h1:62IwC7l8Uw1mxoZe7ewJII0HFHLUMsg04z1BW3JSEfM=
github.com/onflow/flow-go-sdk v1.0.0-preview.30/go.mod h1:PBIk3vLqU1aLdbWPw7ljRDmwSGLcsuk/ipL9eLMgWwc=
github.com/onflow/flow-go-sdk v1.0.0-preview.30.0.20240523120036-f9d51677b347 h1:qXJa8wp2aJLzDO5TVmMxaSHlrZ0/O/HMHzrpFUDP0eo=
github.com/onflow/flow-go-sdk v1.0.0-preview.30.0.20240523120036-f9d51677b347/go.mod h1:J4iKISX976mxV3ReTWiURG/ai50h61s2XJZ3YcK2lCg=
github.com/onflow/flow-nft/lib/go/contracts v1.2.1 h1:woAAS5z651sDpi7ihAHll8NvRS9uFXIXkL6xR+bKFZY=
github.com/onflow/flow-nft/lib/go/contracts v1.2.1/go.mod h1:2gpbza+uzs1k7x31hkpBPlggIRkI53Suo0n2AyA2HcE=
github.com/onflow/flow-nft/lib/go/templates v1.2.0 h1:JSQyh9rg0RC+D1930BiRXN8lrtMs+ubVMK6aQPon6Yc=
Expand Down
74 changes: 4 additions & 70 deletions services/ingestion/subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,79 +8,13 @@ import (

"github.com/onflow/flow-evm-gateway/models"
"github.com/onflow/flow-evm-gateway/services/requester"
"github.com/onflow/flow-evm-gateway/services/testutils"

"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/access/mocks"
flowGo "github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/storage"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
)

type mockClient struct {
*mocks.Client
getLatestBlockHeaderFunc func(context.Context, bool) (*flow.BlockHeader, error)
getBlockHeaderByHeightFunc func(context.Context, uint64) (*flow.BlockHeader, error)
subscribeEventsByBlockHeightFunc func(context.Context, uint64, flow.EventFilter, ...access.SubscribeOption) (<-chan flow.BlockEvents, <-chan error, error)
}

func (c *mockClient) GetBlockHeaderByHeight(ctx context.Context, height uint64) (*flow.BlockHeader, error) {
return c.getBlockHeaderByHeightFunc(ctx, height)
}

func (c *mockClient) GetLatestBlockHeader(ctx context.Context, sealed bool) (*flow.BlockHeader, error) {
return c.getLatestBlockHeaderFunc(ctx, sealed)
}

func (c *mockClient) SubscribeEventsByBlockHeight(
ctx context.Context,
startHeight uint64,
filter flow.EventFilter,
opts ...access.SubscribeOption,
) (<-chan flow.BlockEvents, <-chan error, error) {
return c.subscribeEventsByBlockHeightFunc(ctx, startHeight, filter, opts...)
}

func setupClient(startHeight uint64, endHeight uint64) access.Client {
return &mockClient{
Client: &mocks.Client{},
getLatestBlockHeaderFunc: func(ctx context.Context, sealed bool) (*flow.BlockHeader, error) {
return &flow.BlockHeader{
Height: endHeight,
}, nil
},
getBlockHeaderByHeightFunc: func(ctx context.Context, height uint64) (*flow.BlockHeader, error) {
if height < startHeight || height > endHeight {
return nil, storage.ErrNotFound
}

return &flow.BlockHeader{
Height: height,
}, nil
},
subscribeEventsByBlockHeightFunc: func(
ctx context.Context,
startHeight uint64,
filter flow.EventFilter,
opts ...access.SubscribeOption,
) (<-chan flow.BlockEvents, <-chan error, error) {
events := make(chan flow.BlockEvents)

go func() {
defer close(events)

for i := startHeight; i <= endHeight; i++ {
events <- flow.BlockEvents{
Height: i,
}
}
}()

return events, make(chan error), nil
},
}
}

// this test simulates two previous sporks and current spork
// the subscriber should start with spork1Client then proceed to
// spork2Client and end with currentClient.
Expand All @@ -89,10 +23,10 @@ func Test_Subscribing(t *testing.T) {

const endHeight = 50
sporkClients := []access.Client{
setupClient(1, 10),
setupClient(11, 20),
testutils.SetupClientForRange(1, 10),
testutils.SetupClientForRange(11, 20),
}
currentClient := setupClient(21, endHeight)
currentClient := testutils.SetupClientForRange(21, endHeight)

client, err := requester.NewCrossSporkClient(currentClient, sporkClients, zerolog.Nop())
require.NoError(t, err)
Expand Down
Loading

0 comments on commit aa84d6c

Please sign in to comment.