-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from streamingfast/block_any
v1.0.0 firecore binary, new block format (based on anypb)
- Loading branch information
Showing
170 changed files
with
15,874 additions
and
971 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Build docker image | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v*" | ||
branches: | ||
- "block_any" | ||
workflow_dispatch: | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
strategy: | ||
matrix: | ||
go-version: [ 1.20.x ] | ||
|
||
outputs: | ||
tags: ${{ steps.meta.outputs.tags }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Get repo name | ||
id: extract_repo_name | ||
shell: bash | ||
run: | | ||
echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV | ||
- name: Generate docker tags/labels from github build context | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=tag | ||
type=sha,prefix=,enable=true | ||
type=raw,enable=${{ github.ref == 'refs/heads/develop' }},value=develop | ||
flavor: | | ||
latest=${{ startsWith(github.ref, 'refs/tags/') }} | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
|
||
slack-notifications: | ||
if: ${{ !startsWith(github.ref, 'refs/tags/') && github.event_name != 'workflow_dispatch' }} | ||
needs: [ build ] | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Slack notification | ||
env: | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | ||
uses: Ilshidur/[email protected] | ||
with: | ||
args: | | ||
:done: *${{ github.repository }}* Success building docker image from ${{ github.ref_type }} _${{ github.ref_name }}_ (${{ github.actor }}) :sparkling_heart: ```${{ join(needs.build.outputs.tags, ' ') }}``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.idea | ||
/build | ||
/dist | ||
/dist | ||
.envrc | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM golang:1.21-alpine as build | ||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . ./ | ||
|
||
RUN go build ./cmd/firecore | ||
|
||
#### | ||
|
||
FROM alpine:edge | ||
|
||
|
||
RUN apk --no-cache add \ | ||
ca-certificates htop iotop sysstat \ | ||
strace lsof curl jq tzdata | ||
|
||
RUN mkdir -p /app/ && curl -Lo /app/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.12/grpc_health_probe-linux-amd64 && chmod +x /app/grpc_health_probe | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /app/firecore /app/firecore | ||
|
||
ENTRYPOINT [ "/app/firecore" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package blockpoller | ||
|
||
import ( | ||
"github.com/streamingfast/bstream" | ||
pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type State string | ||
|
||
const ( | ||
ContinuousSegState State = "CONTINUOUS" | ||
IncompleteSegState State = "INCOMPLETE" | ||
) | ||
|
||
func (s State) String() string { | ||
return string(s) | ||
} | ||
|
||
type cursor struct { | ||
currentBlk bstream.BlockRef | ||
currentIncompleteSeg *bstream.BasicBlockRef | ||
state State | ||
logger *zap.Logger | ||
} | ||
|
||
func (s *cursor) addBlk(blk *pbbstream.Block, blockSeen bool, parentSeen bool) { | ||
blkRef := blk.AsRef() | ||
logger := s.logger.With( | ||
zap.Stringer("blk", blkRef), | ||
zap.Stringer("parent_blk", blk.PreviousRef()), | ||
zap.Bool("seen_blk", blockSeen), | ||
zap.Bool("seen_parent", parentSeen), | ||
zap.Stringer("previous_state", s.state), | ||
) | ||
if s.currentIncompleteSeg != nil { | ||
logger = logger.With(zap.Stringer("current_incomplete_seg", *s.currentIncompleteSeg)) | ||
} else { | ||
logger = logger.With(zap.String("current_incomplete_seg", "none")) | ||
|
||
} | ||
|
||
if s.state == IncompleteSegState && blockSeen && parentSeen { | ||
// if we are checking an incomplete segement, and we get a block that is already in the forkdb | ||
// and whose parent is also in the forkdb, then we are back on a continuous segment | ||
s.state = ContinuousSegState | ||
} | ||
s.currentBlk = blkRef | ||
logger.Debug("received block", zap.Stringer("current_state", s.state)) | ||
} | ||
|
||
func (s *cursor) getBlkSegmentNum() bstream.BlockRef { | ||
if s.state == IncompleteSegState { | ||
if s.currentIncompleteSeg == nil { | ||
panic("current incomplete segment is nil, when cursor is incomplete segment, this should never happen") | ||
} | ||
return *s.currentIncompleteSeg | ||
} | ||
return s.currentBlk | ||
} | ||
|
||
func (s *cursor) blkIsConnectedToLib() { | ||
s.state = ContinuousSegState | ||
s.currentIncompleteSeg = nil | ||
} | ||
|
||
func (s *cursor) blkIsNotConnectedToLib() { | ||
if s.state != IncompleteSegState { | ||
s.state = IncompleteSegState | ||
// we don't want to point the current blk since that will change | ||
v := bstream.NewBlockRef(s.currentBlk.ID(), s.currentBlk.Num()) | ||
s.currentIncompleteSeg = &v | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package blockpoller | ||
|
||
import ( | ||
"context" | ||
|
||
pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1" | ||
) | ||
|
||
type BlockFetcher interface { | ||
Fetch(ctx context.Context, blkNum uint64) (*pbbstream.Block, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package blockpoller | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"strings" | ||
"sync" | ||
|
||
pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1" | ||
) | ||
|
||
type BlockHandler interface { | ||
Init() | ||
Handle(blk *pbbstream.Block) error | ||
} | ||
|
||
var _ BlockHandler = (*FireBlockHandler)(nil) | ||
|
||
type FireBlockHandler struct { | ||
blockTypeURL string | ||
init sync.Once | ||
} | ||
|
||
func NewFireBlockHandler(blockTypeURL string) *FireBlockHandler { | ||
return &FireBlockHandler{ | ||
blockTypeURL: clean(blockTypeURL), | ||
} | ||
} | ||
|
||
func (f *FireBlockHandler) Init() { | ||
fmt.Println("FIRE INIT 1.0", f.blockTypeURL) | ||
} | ||
|
||
func (f *FireBlockHandler) Handle(b *pbbstream.Block) error { | ||
typeURL := clean(b.Payload.TypeUrl) | ||
if typeURL != f.blockTypeURL { | ||
return fmt.Errorf("block type url %q does not match expected type %q", typeURL, f.blockTypeURL) | ||
} | ||
|
||
blockLine := fmt.Sprintf( | ||
"FIRE BLOCK %d %s %d %s %d %d %s", | ||
b.Number, | ||
b.Id, | ||
b.ParentNum, | ||
b.ParentId, | ||
b.LibNum, | ||
b.Timestamp.AsTime().UnixNano(), | ||
base64.StdEncoding.EncodeToString(b.Payload.Value), | ||
) | ||
|
||
fmt.Println(blockLine) | ||
return nil | ||
} | ||
|
||
func clean(in string) string { | ||
return strings.Replace(in, "type.googleapis.com/", "", 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package blockpoller | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFireBlockHandler_clean(t *testing.T) { | ||
tests := []struct { | ||
in string | ||
expect string | ||
}{ | ||
{"type.googleapis.com/sf.bstream.v2.Block", "sf.bstream.v2.Block"}, | ||
{"sf.bstream.v2.Block", "sf.bstream.v2.Block"}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.in, func(t *testing.T) { | ||
assert.Equal(t, test.expect, clean(test.in)) | ||
}) | ||
} | ||
|
||
} |
Oops, something went wrong.