Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Merge pull request #715 from iotaledger/feat/workscore-congestion-api
Browse files Browse the repository at this point in the history
Add optional WorkScore to congestion endpoint
  • Loading branch information
muXxer authored Feb 6, 2024
2 parents 4fc7f89 + 247e4e0 commit d0886e4
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 29 deletions.
7 changes: 6 additions & 1 deletion components/restapi/core/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func congestionByAccountAddress(c echo.Context) (*api.CongestionResponse, error)
return nil, err
}

workScore, err := httpserver.ParseWorkScoreQueryParam(c, api.ParameterWorkScore)
if err != nil {
return nil, err
}

commitment := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment()
if commitmentID != iotago.EmptyCommitmentID {
// a commitment ID was provided, so we use the commitment for that ID
Expand Down Expand Up @@ -53,7 +58,7 @@ func congestionByAccountAddress(c echo.Context) (*api.CongestionResponse, error)

return &api.CongestionResponse{
Slot: commitment.Slot(),
Ready: deps.Protocol.Engines.Main.Get().Scheduler.IsBlockIssuerReady(accountID),
Ready: deps.Protocol.Engines.Main.Get().Scheduler.IsBlockIssuerReady(accountID, workScore),
ReferenceManaCost: commitment.ReferenceManaCost(),
BlockIssuanceCredits: acc.Credits.Value,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20240126143305-9caf79103e85
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240126143305-9caf79103e85
github.com/iotaledger/hive.go/stringify v0.0.0-20240126143305-9caf79103e85
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240125161730-faf053c90f7b
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240205143850-53158342305c
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240125161426-1846f6320506
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00
github.com/iotaledger/iota.go/v4 v4.0.0-20240205131109-72af13887479
github.com/iotaledger/iota.go/v4 v4.0.0-20240205135859-2e6b70b484d6
github.com/labstack/echo/v4 v4.11.4
github.com/labstack/gommon v0.4.2
github.com/libp2p/go-libp2p v0.32.2
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240126143305-9caf791
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240126143305-9caf79103e85/go.mod h1:bpJrJ0zYJqHpk8zIB5Sz7r9KCwpgKBaqHby5Uoouipg=
github.com/iotaledger/hive.go/stringify v0.0.0-20240126143305-9caf79103e85 h1:wKzomqZKS4xpefyYOPD9uDqwIz+3UWBRh3SCL2hxEBU=
github.com/iotaledger/hive.go/stringify v0.0.0-20240126143305-9caf79103e85/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240125161730-faf053c90f7b h1:VhO5jTY5hlamUzEUcfFiEaAn5lgVjiySNYM7iOF7BUY=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240125161730-faf053c90f7b/go.mod h1:PQBjosLKS1kL1RK2/PYnZxNHf+Co3JrbpBSgViKITEM=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240205143850-53158342305c h1:pBNv9I+/WSnKK0cxZALKw26BeUlIyjI2eG6Uo5c0DmY=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240205143850-53158342305c/go.mod h1:BIZ+v0l16km86aBp66Shhku6Y5FkrCW6yy2TfebPnp0=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240125161426-1846f6320506 h1:Z7twy8TSuB2Tcjd7pzTtBH3ku90hIMguNSnypswFZyE=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240125161426-1846f6320506/go.mod h1:x8dn1yT4TtyucfQz1Qb4LrqjdxmOMy7oiRiVedLD2/s=
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00 h1:j5udgLtSN6wQgFI9vnhkdJsqsVdJmwtoc0yOmT/Ila4=
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00/go.mod h1:gt+URx7DZu414nZME7jtGgxR4DVTSnNa1jF2trTUTZ0=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205131109-72af13887479 h1:YrPVCuzSLUAeewXjip4B3g8WkpVweXDqtZNt3kppaoU=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205131109-72af13887479/go.mod h1:f7N7GyRbW4B0UWMvCeiXOrYiP9T2HVaQnZqP2zaZSo8=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205135859-2e6b70b484d6 h1:BjXmT1Kt4+KM0pN2ctstZRsJ5syfmE/3O/AoZZbghH8=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205135859-2e6b70b484d6/go.mod h1:f7N7GyRbW4B0UWMvCeiXOrYiP9T2HVaQnZqP2zaZSo8=
github.com/ipfs/boxo v0.17.0 h1:fVXAb12dNbraCX1Cdid5BB6Kl62gVLNVA+e0EYMqAU0=
github.com/ipfs/boxo v0.17.0/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
20 changes: 11 additions & 9 deletions pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,25 @@ func (s *Scheduler) ReadyBlocksCount() int {
return s.basicBuffer.ReadyBlocksCount()
}

func (s *Scheduler) IsBlockIssuerReady(accountID iotago.AccountID, blocks ...*blocks.Block) bool {
func (s *Scheduler) IsBlockIssuerReady(accountID iotago.AccountID, workScores ...iotago.WorkScore) bool {
s.bufferMutex.RLock()
defer s.bufferMutex.RUnlock()

// if the buffer is completely empty, any issuer can issue a block.
if s.basicBuffer.Size() == 0 {
return true
}
work := iotago.WorkScore(0)
// if no specific block(s) is provided, assume max block size
currentAPI := s.apiProvider.CommittedAPI()
if len(blocks) == 0 {
work = currentAPI.MaxBlockWork()
}
for _, block := range blocks {
work += block.WorkScore()

var work iotago.WorkScore
if len(workScores) > 0 {
for _, workScore := range workScores {
work += workScore
}
} else {
// if no specific work score is provided, assume max block work score.
work = s.apiProvider.CommittedAPI().MaxBlockWork()
}

deficit, exists := s.deficits.Get(accountID)
if !exists {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *Scheduler) Shutdown() {
s.TriggerStopped()
}

func (s *Scheduler) IsBlockIssuerReady(_ iotago.AccountID, _ ...*blocks.Block) bool {
func (s *Scheduler) IsBlockIssuerReady(_ iotago.AccountID, _ ...iotago.WorkScore) bool {
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Scheduler interface {
// AddBlock adds a block to the scheduling buffer.
AddBlock(*blocks.Block)
// IsBlockIssuerReady returns true if the block issuer is ready to issuer a block, i.e., if the block issuer were to add a block to the scheduler, would it be scheduled.
IsBlockIssuerReady(iotago.AccountID, ...*blocks.Block) bool
IsBlockIssuerReady(iotago.AccountID, ...iotago.WorkScore) bool
// BasicBufferSize returns the current buffer size of the Scheduler as block count.
BasicBufferSize() int
// ValidatorBufferSize returns the current buffer size of the Scheduler as block count.
Expand Down
4 changes: 2 additions & 2 deletions tools/docker-network/tests/dockerframework.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (d *DockerTestFramework) CreateAccount(opts ...options.Option[builder.Accou
issuerResp, err := clt.BlockIssuance(ctx)
require.NoError(d.Testing, err)

congestionResp, err := clt.Congestion(ctx, accountAddress, lo.PanicOnErr(issuerResp.LatestCommitment.ID()))
congestionResp, err := clt.Congestion(ctx, accountAddress, 0, lo.PanicOnErr(issuerResp.LatestCommitment.ID()))
require.NoError(d.Testing, err)

implicitAddrSigner := iotago.NewInMemoryAddressSigner(iotago.NewAddressKeysForImplicitAccountCreationAddress(receiverAddr.(*iotago.ImplicitAccountCreationAddress), implicitPrivateKey))
Expand Down Expand Up @@ -401,7 +401,7 @@ func (d *DockerTestFramework) DelegateToValidator(from *Account, validator *Node
issuerResp, err := clt.BlockIssuance(ctx)
require.NoError(d.Testing, err)

congestionResp, err := clt.Congestion(ctx, from.AccountAddress, lo.PanicOnErr(issuerResp.LatestCommitment.ID()))
congestionResp, err := clt.Congestion(ctx, from.AccountAddress, 0, lo.PanicOnErr(issuerResp.LatestCommitment.ID()))
require.NoError(d.Testing, err)

delegationOutput := builder.NewDelegationOutputBuilder(validatorAccountAddr.(*iotago.AccountAddress), fundsAddr, fundsUTXOOutput.BaseTokenAmount()).
Expand Down
4 changes: 2 additions & 2 deletions tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20240126143305-9caf79103e85 // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240126143305-9caf79103e85 // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20240126143305-9caf79103e85 // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240125161730-faf053c90f7b // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240205143850-53158342305c // indirect
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240125161426-1846f6320506 // indirect
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00 // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20240205131109-72af13887479 // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20240205135859-2e6b70b484d6 // indirect
github.com/ipfs/boxo v0.17.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions tools/gendoc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240126143305-9caf791
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240126143305-9caf79103e85/go.mod h1:bpJrJ0zYJqHpk8zIB5Sz7r9KCwpgKBaqHby5Uoouipg=
github.com/iotaledger/hive.go/stringify v0.0.0-20240126143305-9caf79103e85 h1:wKzomqZKS4xpefyYOPD9uDqwIz+3UWBRh3SCL2hxEBU=
github.com/iotaledger/hive.go/stringify v0.0.0-20240126143305-9caf79103e85/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240125161730-faf053c90f7b h1:VhO5jTY5hlamUzEUcfFiEaAn5lgVjiySNYM7iOF7BUY=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240125161730-faf053c90f7b/go.mod h1:PQBjosLKS1kL1RK2/PYnZxNHf+Co3JrbpBSgViKITEM=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240205143850-53158342305c h1:pBNv9I+/WSnKK0cxZALKw26BeUlIyjI2eG6Uo5c0DmY=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240205143850-53158342305c/go.mod h1:BIZ+v0l16km86aBp66Shhku6Y5FkrCW6yy2TfebPnp0=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240125161426-1846f6320506 h1:Z7twy8TSuB2Tcjd7pzTtBH3ku90hIMguNSnypswFZyE=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240125161426-1846f6320506/go.mod h1:x8dn1yT4TtyucfQz1Qb4LrqjdxmOMy7oiRiVedLD2/s=
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00 h1:j5udgLtSN6wQgFI9vnhkdJsqsVdJmwtoc0yOmT/Ila4=
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00/go.mod h1:gt+URx7DZu414nZME7jtGgxR4DVTSnNa1jF2trTUTZ0=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205131109-72af13887479 h1:YrPVCuzSLUAeewXjip4B3g8WkpVweXDqtZNt3kppaoU=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205131109-72af13887479/go.mod h1:f7N7GyRbW4B0UWMvCeiXOrYiP9T2HVaQnZqP2zaZSo8=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205135859-2e6b70b484d6 h1:BjXmT1Kt4+KM0pN2ctstZRsJ5syfmE/3O/AoZZbghH8=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205135859-2e6b70b484d6/go.mod h1:f7N7GyRbW4B0UWMvCeiXOrYiP9T2HVaQnZqP2zaZSo8=
github.com/ipfs/boxo v0.17.0 h1:fVXAb12dNbraCX1Cdid5BB6Kl62gVLNVA+e0EYMqAU0=
github.com/ipfs/boxo v0.17.0/go.mod h1:pIZgTWdm3k3pLF9Uq6MB8JEcW07UDwNJjlXW1HELW80=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
2 changes: 1 addition & 1 deletion tools/genesis-snapshot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/iotaledger/hive.go/lo v0.0.0-20240126143305-9caf79103e85
github.com/iotaledger/hive.go/runtime v0.0.0-20240126143305-9caf79103e85
github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000
github.com/iotaledger/iota.go/v4 v4.0.0-20240205131109-72af13887479
github.com/iotaledger/iota.go/v4 v4.0.0-20240205135859-2e6b70b484d6
github.com/mr-tron/base58 v1.2.0
github.com/spf13/pflag v1.0.5
golang.org/x/crypto v0.18.0
Expand Down
4 changes: 2 additions & 2 deletions tools/genesis-snapshot/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/iotaledger/hive.go/stringify v0.0.0-20240126143305-9caf79103e85 h1:wK
github.com/iotaledger/hive.go/stringify v0.0.0-20240126143305-9caf79103e85/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00 h1:j5udgLtSN6wQgFI9vnhkdJsqsVdJmwtoc0yOmT/Ila4=
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00/go.mod h1:gt+URx7DZu414nZME7jtGgxR4DVTSnNa1jF2trTUTZ0=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205131109-72af13887479 h1:YrPVCuzSLUAeewXjip4B3g8WkpVweXDqtZNt3kppaoU=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205131109-72af13887479/go.mod h1:f7N7GyRbW4B0UWMvCeiXOrYiP9T2HVaQnZqP2zaZSo8=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205135859-2e6b70b484d6 h1:BjXmT1Kt4+KM0pN2ctstZRsJ5syfmE/3O/AoZZbghH8=
github.com/iotaledger/iota.go/v4 v4.0.0-20240205135859-2e6b70b484d6/go.mod h1:f7N7GyRbW4B0UWMvCeiXOrYiP9T2HVaQnZqP2zaZSo8=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
Expand Down

0 comments on commit d0886e4

Please sign in to comment.