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

Bump go-spacemesh to v1.6.0 #153

Merged
merged 1 commit into from
Jun 29, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

env:
go-version: '1.22.2'
go-version: '1.22.3'

# Trigger the workflow on all pull requests, and on push to specific branches
on:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.apiserver
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.2-alpine AS build
FROM golang:1.22.3-alpine AS build
WORKDIR /src
COPY . .
RUN apk add --no-cache gcc musl-dev
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.collector
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.2-alpine AS build
FROM golang:1.22.3-alpine AS build
WORKDIR /src
COPY . .
RUN apk add --no-cache gcc musl-dev
Expand Down
2 changes: 1 addition & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Listener interface {
GetTransactions(parent context.Context, query *bson.D, opts ...*options.FindOptions) ([]model.Transaction, error)
UpdateTransactionState(parent context.Context, id string, state int32) error
UpdateEpochStats(layer uint32)
OnActivation(atx *types.VerifiedActivationTx)
OnActivation(atx *types.ActivationTx)
GetLastActivationReceived() int64
RecalculateEpochStats()
OnActivations(atxs []*model.Activation)
Expand Down
8 changes: 4 additions & 4 deletions collector/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *Collector) StartHttpServer(apiHost string, apiPort int) {

log.Info("http syncing atxs from %d", timestamp)
go func() {
err = c.dbClient.GetAtxsReceivedAfter(c.db, timestamp, func(atx *types.VerifiedActivationTx) bool {
err = c.dbClient.GetAtxsReceivedAfter(c.db, timestamp, func(atx *types.ActivationTx) bool {
c.listener.OnActivation(atx)
return true
})
Expand All @@ -66,7 +66,7 @@ func (c *Collector) StartHttpServer(apiHost string, apiPort int) {
log.Info("http syncing atxs from %d", timestamp)
go func() {
var atxs []*model.Activation
err = c.dbClient.GetAtxsReceivedAfter(c.db, timestamp, func(atx *types.VerifiedActivationTx) bool {
err = c.dbClient.GetAtxsReceivedAfter(c.db, timestamp, func(atx *types.ActivationTx) bool {
atxs = append(atxs, model.NewActivation(atx))
return true
})
Expand All @@ -90,7 +90,7 @@ func (c *Collector) StartHttpServer(apiHost string, apiPort int) {

log.Info("http syncing atxs for epoch %s", epoch)
go func() {
err = c.dbClient.GetAtxsByEpoch(c.db, epochId, func(atx *types.VerifiedActivationTx) bool {
err = c.dbClient.GetAtxsByEpoch(c.db, epochId, func(atx *types.ActivationTx) bool {
c.listener.OnActivation(atx)
return true
})
Expand Down Expand Up @@ -123,7 +123,7 @@ func (c *Collector) StartHttpServer(apiHost string, apiPort int) {
for page := 0; page < totalPages; page++ {
offset := page * batchSize
var atxs []*model.Activation
err = c.dbClient.GetAtxsByEpochPaginated(c.db, epochId, int64(batchSize), int64(offset), func(atx *types.VerifiedActivationTx) bool {
err = c.dbClient.GetAtxsByEpochPaginated(c.db, epochId, int64(batchSize), int64(offset), func(atx *types.ActivationTx) bool {
atxs = append(atxs, model.NewActivation(atx))
return true
})
Expand Down
2 changes: 1 addition & 1 deletion collector/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (c *Collector) syncActivations() error {
log.Info("Syncing activations from %d", received)

var atxs []*model.Activation
err := c.dbClient.GetAtxsReceivedAfter(c.db, received, func(atx *types.VerifiedActivationTx) bool {
err := c.dbClient.GetAtxsReceivedAfter(c.db, received, func(atx *types.ActivationTx) bool {
atxs = append(atxs, model.NewActivation(atx))
return true
})
Expand Down
80 changes: 38 additions & 42 deletions collector/sql/atxs.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package sql

import (
"fmt"
sqlite "github.com/go-llsqlite/crawshaw"
"github.com/spacemeshos/explorer-backend/utils"
"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/sql"
"github.com/spacemeshos/go-spacemesh/sql/atxs"
"time"
)

const fullQuery = `select id,
(select atx from atx_blobs b where a.id = b.id) as atx,
base_tick_height, tick_count, pubkey,
effective_num_units, received, epoch, sequence, coinbase, validity
from atxs a`
// Query to retrieve ATXs.
// Can't use inner join for the ATX blob here b/c this will break
// filters that refer to the id column.
const fieldsQuery = `select
atxs.id, atxs.nonce, atxs.base_tick_height, atxs.tick_count, atxs.pubkey, atxs.effective_num_units,
atxs.received, atxs.epoch, atxs.sequence, atxs.coinbase, atxs.validity, atxs.prev_id, atxs.commitment_atx`

type decoderCallback func(*types.VerifiedActivationTx, error) bool
const fullQuery = fieldsQuery + ` from atxs`

type decoderCallback func(*types.ActivationTx) bool

func decoder(fn decoderCallback) sql.Decoder {
return func(stmt *sql.Statement) bool {
Expand All @@ -26,52 +27,49 @@ func decoder(fn decoderCallback) sql.Decoder {
id types.ATXID
)
stmt.ColumnBytes(0, id[:])
checkpointed := stmt.ColumnLen(1) == 0
if !checkpointed {
var atxV1 wire.ActivationTxV1
if _, err := codec.DecodeFrom(stmt.ColumnReader(1), &atxV1); err != nil {
return fn(nil, fmt.Errorf("decode %w", err))
}
a = *wire.ActivationTxFromWireV1(&atxV1)
}
a.SetID(id)
baseTickHeight := uint64(stmt.ColumnInt64(2))
tickCount := uint64(stmt.ColumnInt64(3))
a.VRFNonce = types.VRFPostIndex(stmt.ColumnInt64(1))
a.BaseTickHeight = uint64(stmt.ColumnInt64(2))
a.TickCount = uint64(stmt.ColumnInt64(3))
stmt.ColumnBytes(4, a.SmesherID[:])
effectiveNumUnits := uint32(stmt.ColumnInt32(5))
a.SetEffectiveNumUnits(effectiveNumUnits)
if checkpointed {
a.NumUnits = uint32(stmt.ColumnInt32(5))
// Note: received is assigned `0` for checkpointed ATXs.
// We treat `0` as 'zero time'.
// We could use `NULL` instead, but the column has "NOT NULL" constraint.
// In future, consider changing the schema to allow `NULL` for received.
if received := stmt.ColumnInt64(6); received == 0 {
a.SetGolden()
a.NumUnits = effectiveNumUnits
a.SetReceived(time.Time{})
} else {
a.SetReceived(time.Unix(0, stmt.ColumnInt64(6)).Local())
a.SetReceived(time.Unix(0, received).Local())
}
a.PublishEpoch = types.EpochID(uint32(stmt.ColumnInt(7)))
a.Sequence = uint64(stmt.ColumnInt64(8))
stmt.ColumnBytes(9, a.Coinbase[:])
a.SetValidity(types.Validity(stmt.ColumnInt(10)))
v, err := a.Verify(baseTickHeight, tickCount)
if err != nil {
return fn(nil, err)
if stmt.ColumnType(11) != sqlite.SQLITE_NULL {
stmt.ColumnBytes(11, a.PrevATXID[:])
}
if stmt.ColumnType(12) != sqlite.SQLITE_NULL {
a.CommitmentATX = new(types.ATXID)
stmt.ColumnBytes(12, a.CommitmentATX[:])
}
return fn(v, nil)

return fn(&a)
}
}

func (c *Client) GetAtxsReceivedAfter(db *sql.Database, ts int64, fn func(tx *types.VerifiedActivationTx) bool) error {
func (c *Client) GetAtxsReceivedAfter(db *sql.Database, ts int64, fn func(tx *types.ActivationTx) bool) error {
var derr error
_, err := db.Exec(
fullQuery+` WHERE received > ?1`,
func(stmt *sql.Statement) {
stmt.BindInt64(1, ts)
},
decoder(func(atx *types.VerifiedActivationTx, err error) bool {
decoder(func(atx *types.ActivationTx) bool {
if atx != nil {
return fn(atx)
}
derr = err
return derr == nil
return true
}),
)
if err != nil {
Expand All @@ -80,19 +78,18 @@ func (c *Client) GetAtxsReceivedAfter(db *sql.Database, ts int64, fn func(tx *ty
return derr
}

func (c *Client) GetAtxsByEpoch(db *sql.Database, epoch int64, fn func(tx *types.VerifiedActivationTx) bool) error {
func (c *Client) GetAtxsByEpoch(db *sql.Database, epoch int64, fn func(tx *types.ActivationTx) bool) error {
var derr error
_, err := db.Exec(
fullQuery+` WHERE epoch = ?1 ORDER BY epoch asc, id asc`,
func(stmt *sql.Statement) {
stmt.BindInt64(1, epoch)
},
decoder(func(atx *types.VerifiedActivationTx, err error) bool {
decoder(func(atx *types.ActivationTx) bool {
if atx != nil {
return fn(atx)
}
derr = err
return derr == nil
return true
}),
)
if err != nil {
Expand All @@ -117,7 +114,7 @@ func (c *Client) CountAtxsByEpoch(db *sql.Database, epoch int64) (int, error) {
return totalCount, nil
}

func (c *Client) GetAtxsByEpochPaginated(db *sql.Database, epoch, limit, offset int64, fn func(tx *types.VerifiedActivationTx) bool) error {
func (c *Client) GetAtxsByEpochPaginated(db *sql.Database, epoch, limit, offset int64, fn func(tx *types.ActivationTx) bool) error {
var derr error
_, err := db.Exec(
fullQuery+` WHERE epoch = ?1 ORDER BY epoch asc, id asc LIMIT ?2 OFFSET ?3`,
Expand All @@ -126,12 +123,11 @@ func (c *Client) GetAtxsByEpochPaginated(db *sql.Database, epoch, limit, offset
stmt.BindInt64(2, limit)
stmt.BindInt64(3, offset)
},
decoder(func(atx *types.VerifiedActivationTx, err error) bool {
decoder(func(atx *types.ActivationTx) bool {
if atx != nil {
return fn(atx)
}
derr = err
return derr == nil
return true
}),
)
if err != nil {
Expand All @@ -140,7 +136,7 @@ func (c *Client) GetAtxsByEpochPaginated(db *sql.Database, epoch, limit, offset
return derr
}

func (c *Client) GetAtxById(db *sql.Database, id string) (*types.VerifiedActivationTx, error) {
func (c *Client) GetAtxById(db *sql.Database, id string) (*types.ActivationTx, error) {
idBytes, err := utils.StringToBytes(id)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions collector/sql/layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func getMeshTransactions(db *sql.Database, ids []types.TransactionID) ([]*types.
return mtxs, missing
}

func GetATXs(db *sql.Database, atxIds []types.ATXID) (map[types.ATXID]*types.VerifiedActivationTx, []types.ATXID) {
func GetATXs(db *sql.Database, atxIds []types.ATXID) (map[types.ATXID]*types.ActivationTx, []types.ATXID) {
var mIds []types.ATXID
a := make(map[types.ATXID]*types.VerifiedActivationTx, len(atxIds))
a := make(map[types.ATXID]*types.ActivationTx, len(atxIds))
for _, id := range atxIds {
t, err := getFullAtx(db, id)
if err != nil {
Expand All @@ -132,7 +132,7 @@ func GetATXs(db *sql.Database, atxIds []types.ATXID) (map[types.ATXID]*types.Ver
return a, mIds
}

func getFullAtx(db *sql.Database, id types.ATXID) (*types.VerifiedActivationTx, error) {
func getFullAtx(db *sql.Database, id types.ATXID) (*types.ActivationTx, error) {
if id == types.EmptyATXID {
return nil, errors.New("trying to fetch empty atx id")
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func castTransaction(t *types.Transaction) *pb.Transaction {
return tx
}

func convertActivation(a *types.VerifiedActivationTx) *pb.Activation {
func convertActivation(a *types.ActivationTx) *pb.Activation {
return &pb.Activation{
Id: &pb.ActivationId{Id: a.ID().Bytes()},
Layer: &pb.LayerNumber{Number: a.PublishEpoch.Uint32()},
Expand Down
8 changes: 4 additions & 4 deletions collector/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type DatabaseClient interface {
GetLayerRewards(db *sql.Database, lid types.LayerID) (rst []*types.Reward, err error)
GetAllRewards(db *sql.Database) (rst []*types.Reward, err error)
AccountsSnapshot(db *sql.Database, lid types.LayerID) (rst []*types.Account, err error)
GetAtxsReceivedAfter(db *sql.Database, ts int64, fn func(tx *types.VerifiedActivationTx) bool) error
GetAtxsByEpoch(db *sql.Database, epoch int64, fn func(tx *types.VerifiedActivationTx) bool) error
GetAtxsReceivedAfter(db *sql.Database, ts int64, fn func(tx *types.ActivationTx) bool) error
GetAtxsByEpoch(db *sql.Database, epoch int64, fn func(tx *types.ActivationTx) bool) error
CountAtxsByEpoch(db *sql.Database, epoch int64) (int, error)
GetAtxsByEpochPaginated(db *sql.Database, epoch, limit, offset int64, fn func(tx *types.VerifiedActivationTx) bool) error
GetAtxById(db *sql.Database, id string) (*types.VerifiedActivationTx, error)
GetAtxsByEpochPaginated(db *sql.Database, epoch, limit, offset int64, fn func(tx *types.ActivationTx) bool) error
GetAtxById(db *sql.Database, id string) (*types.ActivationTx, error)
}

type Client struct{}
Expand Down
42 changes: 22 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
module github.com/spacemeshos/explorer-backend

go 1.22.2
go 1.22.3

toolchain go1.22.4

require (
github.com/gofiber/fiber/v2 v2.52.1
github.com/golang/protobuf v1.5.4
github.com/gorilla/websocket v1.5.1
github.com/labstack/echo/v4 v4.9.1
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/client_golang v1.19.1
github.com/spacemeshos/address v0.0.0-20220829090052-44ab32617871
github.com/spacemeshos/api/release/go v1.37.0
github.com/spacemeshos/api/release/go v1.49.0
github.com/spacemeshos/go-scale v1.2.0
github.com/spacemeshos/go-spacemesh v1.5.3
github.com/spacemeshos/go-spacemesh v1.6.0
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.1
github.com/urfave/cli/v2 v2.27.2
go.mongodb.org/mongo-driver v1.10.1
golang.org/x/net v0.23.0
golang.org/x/net v0.25.0
golang.org/x/sync v0.7.0
google.golang.org/grpc v1.63.2
google.golang.org/grpc v1.64.0
)

require (
Expand All @@ -31,17 +33,17 @@ require (
github.com/c0mm4nd/go-ripemd v0.0.0-20200326052756-bd1759ad7d10 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-llsqlite/crawshaw v0.5.1 // indirect
github.com/go-llsqlite/crawshaw v0.5.3 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/huandu/xstrings v1.2.0 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -53,12 +55,12 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.52.3 // indirect
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spacemeshos/merkle-tree v0.2.3 // indirect
github.com/spacemeshos/poet v0.10.2 // indirect
github.com/spacemeshos/poet v0.10.3 // indirect
github.com/spacemeshos/post v0.12.6 // indirect
github.com/spacemeshos/sha256-simd v0.1.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
Expand All @@ -68,18 +70,18 @@ require (
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading