Skip to content

Commit

Permalink
Merge pull request #920 from iotaledger/feat/inx-blockissuance
Browse files Browse the repository at this point in the history
Extend INX BlockIssuance api
  • Loading branch information
muXxer authored Apr 19, 2024
2 parents d469894 + d6d68b8 commit 15beb39
Show file tree
Hide file tree
Showing 6 changed files with 394 additions and 337 deletions.
2 changes: 1 addition & 1 deletion components/debugapi/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func configure() error {
return c.String(http.StatusInternalServerError, err.Error())
}

return c.Blob(http.StatusOK, echo.MIMEApplicationJSONCharsetUTF8, blockJSON)
return c.Blob(http.StatusOK, echo.MIMEApplicationJSON, blockJSON)
})

routeGroup.GET(RouteValidators, func(c echo.Context) error {
Expand Down
69 changes: 63 additions & 6 deletions components/inx/server_issuance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,78 @@ package inx

import (
"context"
"time"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/hive.go/serializer/v2/serix"
inx "github.com/iotaledger/inx/go"
"github.com/iotaledger/iota-core/pkg/protocol/engine/mempool"
iotago "github.com/iotaledger/iota.go/v4"
)

func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.TipsResponse, error) {
references := deps.Protocol.Engines.Main.Get().TipSelection.SelectTips(int(req.GetCount()), int(req.GetCount()), int(req.GetCount()))
func (s *Server) ReadBlockIssuance(_ context.Context, req *inx.BlockIssuanceRequest) (*inx.BlockIssuanceResponse, error) {
references := deps.Protocol.Engines.Main.Get().TipSelection.SelectTips(int(req.GetMaxStrongParentsCount()), int(req.GetMaxShallowLikeParentsCount()), int(req.GetMaxWeakParentsCount()))
if len(references[iotago.StrongParentType]) == 0 {
return nil, status.Errorf(codes.Unavailable, "no strong parents available")
}

// get the latest parent block issuing time
var latestParentBlockIssuingTime time.Time

checkParent := func(parentBlockID iotago.BlockID) error {
parentBlock, exists := deps.Protocol.Engines.Main.Get().Block(parentBlockID)
if !exists {
// check if this is the genesis block
if parentBlockID == deps.Protocol.CommittedAPI().ProtocolParameters().GenesisBlockID() {
return nil
}

// or a root block
rootBlocks, err := deps.Protocol.Engines.Main.Get().Storage.RootBlocks(parentBlockID.Slot())
if err != nil {
return status.Errorf(codes.Internal, "failed to get root blocks for slot %d: %s", parentBlockID.Slot(), err.Error())
}

isRootBlock, err := rootBlocks.Has(parentBlockID)
if err != nil {
return status.Errorf(codes.Internal, "failed to check if block %s is a root block: %s", parentBlockID, err.Error())
}

if isRootBlock {
return nil
}

return status.Errorf(codes.NotFound, "no block found for block ID %s", parentBlockID)
}

if latestParentBlockIssuingTime.Before(parentBlock.ProtocolBlock().Header.IssuingTime) {
latestParentBlockIssuingTime = parentBlock.ProtocolBlock().Header.IssuingTime
}

return nil
}

for _, parentType := range []iotago.ParentsType{iotago.StrongParentType, iotago.WeakParentType, iotago.ShallowLikeParentType} {
for _, parentBlockID := range references[parentType] {
if err := checkParent(parentBlockID); err != nil {
return nil, ierrors.Wrap(err, "failed to retrieve parents")
}
}
}

latestCommitment := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment()

return &inx.TipsResponse{
StrongTips: inx.NewBlockIds(references[iotago.StrongParentType]),
WeakTips: inx.NewBlockIds(references[iotago.WeakParentType]),
ShallowLikeTips: inx.NewBlockIds(references[iotago.ShallowLikeParentType]),
return &inx.BlockIssuanceResponse{
StrongParents: inx.NewBlockIds(references[iotago.StrongParentType]),
WeakParents: inx.NewBlockIds(references[iotago.WeakParentType]),
ShallowLikeParents: inx.NewBlockIds(references[iotago.ShallowLikeParentType]),
LatestParentBlockIssuingTime: inx.TimeToUint64(latestParentBlockIssuingTime),
LatestFinalizedSlot: uint32(deps.Protocol.Engines.Main.Get().SyncManager.LatestFinalizedSlot()),
LatestCommitment: inx.NewCommitmentWithBytes(latestCommitment.ID(), latestCommitment.Data()),
}, nil
}

Expand Down
111 changes: 55 additions & 56 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ require (
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.1
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/iotaledger/hive.go/ads v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/app v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/constraints v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/crypto v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/db v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/ds v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/ierrors v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/kvstore v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/lo v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/log v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/runtime v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/sql v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/hive.go/stringify v0.0.0-20240326102522-2e37ab3611a3
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240307101848-db58eb9353ec
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240307100839-48553e1d2022
github.com/iotaledger/iota.go/v4 v4.0.0-20240415115618-57e9e887bf49
github.com/labstack/echo/v4 v4.11.4
github.com/iotaledger/hive.go/ads v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/app v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/constraints v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/crypto v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/db v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/ds v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/ierrors v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/kvstore v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/lo v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/log v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/runtime v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/sql v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/hive.go/stringify v0.0.0-20240419094509-31dbb7270ad9
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240419103152-aa12c9f5bd66
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240419095729-912f1c2df45d
github.com/iotaledger/iota.go/v4 v4.0.0-20240419095144-054bd7d2ba61
github.com/labstack/echo/v4 v4.12.0
github.com/labstack/gommon v0.4.2
github.com/libp2p/go-libp2p v0.33.1
github.com/libp2p/go-libp2p v0.33.2
github.com/libp2p/go-libp2p-kad-dht v0.25.2
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multiaddr v0.12.2
github.com/multiformats/go-multiaddr v0.12.3
github.com/multiformats/go-varint v0.0.7
github.com/otiai10/copy v1.14.0
github.com/prometheus/client_golang v1.19.0
Expand All @@ -45,28 +45,28 @@ require (
github.com/zyedidia/generic v1.2.1
go.uber.org/atomic v1.11.0
go.uber.org/dig v1.17.1
golang.org/x/crypto v0.21.0
google.golang.org/grpc v1.62.1
golang.org/x/crypto v0.22.0
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
gorm.io/gorm v1.25.8
gorm.io/gorm v1.25.9
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.3 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/ethereum/go-ethereum v1.13.14 // indirect
github.com/elastic/gosigar v0.14.3 // indirect
github.com/ethereum/go-ethereum v1.13.15 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/felixge/fgprof v0.9.4 // indirect
github.com/flynn/noise v1.1.0 // indirect
Expand All @@ -79,12 +79,11 @@ require (
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20240319011627-a57c5dfe54fd // indirect
github.com/google/pprof v0.0.0-20240416155748-26353dc0451f // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
Expand All @@ -93,8 +92,8 @@ require (
github.com/huin/goupnp v1.3.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect
github.com/iotaledger/iota-crypto-demo v0.0.0-20240320124000-d02f37a4fdff // indirect
github.com/ipfs/boxo v0.18.0 // indirect
github.com/iotaledger/iota-crypto-demo v0.0.0-20240419094816-40260bb800f7 // indirect
github.com/ipfs/boxo v0.19.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
Expand All @@ -109,7 +108,7 @@ require (
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
Expand All @@ -130,7 +129,7 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/miekg/dns v1.1.58 // indirect
github.com/miekg/dns v1.1.59 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
Expand All @@ -145,23 +144,23 @@ require (
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.5.0 // indirect
github.com/onsi/ginkgo/v2 v2.16.0 // indirect
github.com/onsi/ginkgo/v2 v2.17.1 // indirect
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/petermattis/goid v0.0.0-20240327183114-c42a807a84ba // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pokt-network/smt v0.9.2 // indirect
github.com/pokt-network/smt v0.10.2 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.50.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.42.0 // indirect
github.com/quic-go/webtransport-go v0.6.0 // indirect
github.com/quic-go/webtransport-go v0.7.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
Expand All @@ -171,27 +170,27 @@ require (
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/fx v1.20.1 // indirect
go.opentelemetry.io/otel v1.25.0 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
go.uber.org/fx v1.21.0 // 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/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/image v0.15.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.19.0 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8 // indirect
golang.org/x/tools v0.20.0 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.7 // indirect
gorm.io/driver/sqlite v1.5.5 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
lukechampine.com/blake3 v1.2.2 // indirect
)
Loading

0 comments on commit 15beb39

Please sign in to comment.