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

Devnet-11 branch #42

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
build_binaries:
name: "Build binaries"
uses: ./.github/workflows/_shared-build.yaml

10 changes: 10 additions & 0 deletions Dockerfile-stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# final stage
FROM debian:stable-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates
RUN update-ca-certificates
COPY bin/* /app
EXPOSE 8080
ENTRYPOINT ["./dora-explorer"]
CMD []
25 changes: 3 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# dora
EXECUTABLE=explorer
WINDOWS=$(EXECUTABLE)_windows_amd64.exe
LINUX=$(EXECUTABLE)_linux_amd64
DARWIN=$(EXECUTABLE)_darwin_amd64
VERSION := $(shell git rev-parse --short HEAD)
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
VERSION := $(shell git rev-parse --short HEAD)

Expand All @@ -18,23 +13,9 @@ all: test build
test:
go test ./...

build: windows linux darwin
build:
@echo version: $(VERSION)

windows: $(WINDOWS)

linux: $(LINUX)

darwin: $(DARWIN)

$(WINDOWS):
env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -v -o bin/$(WINDOWS) -ldflags="-s -w $(GOLDFLAGS)" ./cmd/explorer

$(LINUX):
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -v -o bin/$(LINUX) -ldflags="-s -w $(GOLDFLAGS)" ./cmd/explorer

$(DARWIN):
env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -v -o bin/$(DARWIN) -ldflags="-s -w $(GOLDFLAGS)" ./cmd/explorer
env CGO_ENABLED=1 go build -v -o bin/ -ldflags="-s -w $(GOLDFLAGS)" ./cmd/*

clean:
rm -f $(WINDOWS) $(LINUX) $(DARWIN)
rm -f bin/*
File renamed without changes.
5 changes: 5 additions & 0 deletions indexer/cache_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ func (cache *indexerCache) processCachePersistence() error {
}

for _, epochStats := range persistEpochs {
err := persistSlotAssignments(epochStats, tx)
if err != nil {
return err
}

if !epochStats.isInDb {
dbEpoch, _ := cache.indexer.buildLiveEpoch(epochStats.Epoch, epochStats)
if dbEpoch != nil {
Expand Down
3 changes: 3 additions & 0 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ func (indexer *Indexer) GetHeadForks(readyOnly bool) []*HeadFork {
continue
}
cHeadSlot, cHeadRoot, _ := client.GetLastHead()
if cHeadSlot < 0 {
cHeadSlot = 0
}
var matchingFork *HeadFork
for _, fork := range headForks {
if bytes.Equal(fork.Root, cHeadRoot) || indexer.indexerCache.isCanonicalBlock(cHeadRoot, fork.Root) {
Expand Down
37 changes: 26 additions & 11 deletions indexer/write_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ import (
"github.com/pk910/dora/utils"
)

func persistSlotAssignments(epochStats *EpochStats, tx *sqlx.Tx) error {
// insert slot assignments
firstSlot := epochStats.Epoch * utils.Config.Chain.Config.SlotsPerEpoch
if epochStats.proposerAssignments != nil {
slotAssignments := make([]*dbtypes.SlotAssignment, utils.Config.Chain.Config.SlotsPerEpoch)
for slotIdx := uint64(0); slotIdx < utils.Config.Chain.Config.SlotsPerEpoch; slotIdx++ {
slot := firstSlot + slotIdx
slotAssignments[slotIdx] = &dbtypes.SlotAssignment{
Slot: slot,
Proposer: epochStats.proposerAssignments[slot],
}
}
err := db.InsertSlotAssignments(slotAssignments, tx)
if err != nil {
return fmt.Errorf("error while adding proposer assignments to db: %w", err)
}
}
return nil
}

func persistEpochData(epoch uint64, blockMap map[uint64]*CacheBlock, epochStats *EpochStats, epochVotes *EpochVotes, tx *sqlx.Tx) error {
commitTx := false
if tx == nil {
Expand All @@ -29,21 +49,16 @@ func persistEpochData(epoch uint64, blockMap map[uint64]*CacheBlock, epochStats
})

// insert slot assignments
firstSlot := epoch * utils.Config.Chain.Config.SlotsPerEpoch
if epochStats.proposerAssignments != nil {
slotAssignments := make([]*dbtypes.SlotAssignment, utils.Config.Chain.Config.SlotsPerEpoch)
for slotIdx := uint64(0); slotIdx < utils.Config.Chain.Config.SlotsPerEpoch; slotIdx++ {
slot := firstSlot + slotIdx
slotAssignments[slotIdx] = &dbtypes.SlotAssignment{
Slot: slot,
Proposer: epochStats.proposerAssignments[slot],
}
}
db.InsertSlotAssignments(slotAssignments, tx)
err := persistSlotAssignments(epochStats, tx)
if err != nil {
return err
}

// insert epoch
db.InsertEpoch(dbEpoch, tx)
if err != nil {
return fmt.Errorf("error while saving epoch to db: %w", err)
}

if commitTx {
logger.Infof("commit transaction")
Expand Down
44 changes: 38 additions & 6 deletions services/beaconservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ func (bs *BeaconService) GetProposerAssignments(firstEpoch uint64, lastEpoch uin
}

if firstEpoch >= uint64(idxMinEpoch) {
for epochIdx := int64(firstEpoch); epochIdx >= int64(idxMinEpoch) && epochIdx >= int64(lastEpoch); epochIdx-- {
firstMissingEpoch := int64(-1)
for epochIdx := int64(firstEpoch); epochIdx >= idxMinEpoch && epochIdx >= int64(lastEpoch); epochIdx-- {
epoch = uint64(epochIdx)
epochStats := bs.indexer.GetCachedEpochStats(epoch)

Expand All @@ -347,13 +348,22 @@ func (bs *BeaconService) GetProposerAssignments(firstEpoch uint64, lastEpoch uin
for slot, vidx := range proposers {
proposerAssignments[slot] = vidx
}
continue
}
}

if firstMissingEpoch == -1 {
firstMissingEpoch = int64(epoch)
}
}
if epoch <= lastEpoch {
if epoch <= lastEpoch && firstMissingEpoch == -1 {
return
}
firstEpoch = epoch
if firstMissingEpoch == -1 {
firstEpoch = uint64(idxMinEpoch)
} else {
firstEpoch = uint64(firstMissingEpoch)
}
}

// load from db
Expand Down Expand Up @@ -572,13 +582,35 @@ func (bs *BeaconService) GetDbBlocksByFilter(filter *dbtypes.BlockFilter, pageId
idxHeadSlot := bs.indexer.GetHighestSlot()
idxHeadEpoch := utils.EpochOfSlot(idxHeadSlot)
idxMinEpoch := utils.EpochOfSlot(uint64(idxMinSlot))
var storedProposerAssignments []*dbtypes.SlotAssignment

for epochIdx := int64(idxHeadEpoch); epochIdx >= int64(idxMinEpoch); epochIdx-- {
epoch := uint64(epochIdx)
var proposerAssignments map[uint64]uint64
epochStats := bs.indexer.GetCachedEpochStats(epoch)
if epochStats == nil {
continue
if epochStats != nil {
proposerAssignments = epochStats.GetProposerAssignments()
} else {
if storedProposerAssignments == nil {
// get all unfinalized proposer assignments from db
firstSlot := idxHeadEpoch * utils.Config.Chain.Config.SlotsPerEpoch
lastSlot := idxMinEpoch * utils.Config.Chain.Config.SlotsPerEpoch
storedProposerAssignments = db.GetSlotAssignmentsForSlots(firstSlot, lastSlot)
}
proposerAssignments = map[uint64]uint64{}
firstSlot := epoch * utils.Config.Chain.Config.SlotsPerEpoch
lastSlot := firstSlot + utils.Config.Chain.Config.SlotsPerEpoch - 1
for slot := firstSlot; slot <= lastSlot; slot++ {
proposerAssignments[slot] = math.MaxInt64
}
for _, dbProposerAssignment := range storedProposerAssignments {
if dbProposerAssignment.Slot >= firstSlot && dbProposerAssignment.Slot <= lastSlot {
proposerAssignments[dbProposerAssignment.Slot] = dbProposerAssignment.Proposer
}
}
}
for slot, assigned := range epochStats.GetProposerAssignments() {

for slot, assigned := range proposerAssignments {
if proposedMap[slot] {
continue
}
Expand Down