Skip to content

Commit

Permalink
Merge pull request #352 from iotaledger/align-naming
Browse files Browse the repository at this point in the history
Update parameter naming to spec
  • Loading branch information
muXxer authored Sep 21, 2023
2 parents de5a03c + d1b9851 commit cec44e5
Show file tree
Hide file tree
Showing 53 changed files with 133 additions and 178 deletions.
2 changes: 1 addition & 1 deletion components/dashboard/jsonresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func NewSlotDetails(commitment *model.Commitment, diffs *utxoledger.SlotDiff) *S

return &SlotDetailsResponse{
Index: uint64(commitment.Index()),
PrevID: commitment.PrevID().ToHex(),
PrevID: commitment.PreviousCommitmentID().ToHex(),
RootsID: commitment.RootsID().ToHex(),
CumulativeWeight: commitment.CumulativeWeight(),
CreatedOutputs: createdOutputs,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/iotaledger/hive.go/stringify v0.0.0-20230912172434-dc477e1f5140
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230919065227-618931c246c5
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230918132810-48814818bff9
github.com/iotaledger/iota.go/v4 v4.0.0-20230920081018-054aaef28ba2
github.com/iotaledger/iota.go/v4 v4.0.0-20230921110244-f4f25eb27e05
github.com/labstack/echo/v4 v4.11.1
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.30.0
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230919065227-618931c246c5 h1:7GuYO
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230919065227-618931c246c5/go.mod h1:luLlwdZT26MqUWBbiEOYxBwYLVrfz+65D+Tme84+Slw=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230918132810-48814818bff9 h1:BJb6+fF7zTyrbKQY3JG1Hiw6klONR4anwCFOcNdWu9o=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230918132810-48814818bff9/go.mod h1:B7gyJP6GshCSlEmY3CxEk5TZdsMs3UNz5U92hkFDdMs=
github.com/iotaledger/iota.go/v4 v4.0.0-20230913143616-917572c7752d h1:p9IchKq6kft758XDlnN/tAEXJMXGlmQPmbdxolba1gs=
github.com/iotaledger/iota.go/v4 v4.0.0-20230913143616-917572c7752d/go.mod h1:DWCa+mXRTGWBV0EHVuvToUxAEcICe2Pab9hBlxBamKo=
github.com/iotaledger/iota.go/v4 v4.0.0-20230920081018-054aaef28ba2 h1:N1w2b3d7r25Fj2WvHVeTyz1Imbw+dpHqrQ8p9GBWHhk=
github.com/iotaledger/iota.go/v4 v4.0.0-20230920081018-054aaef28ba2/go.mod h1:DWCa+mXRTGWBV0EHVuvToUxAEcICe2Pab9hBlxBamKo=
github.com/iotaledger/iota.go/v4 v4.0.0-20230920163540-ec641f64d740 h1:+/4iXhSsTfOgSqgFluciagiOrBN6GUfK4vhI4wHlRMU=
github.com/iotaledger/iota.go/v4 v4.0.0-20230920163540-ec641f64d740/go.mod h1:DWCa+mXRTGWBV0EHVuvToUxAEcICe2Pab9hBlxBamKo=
github.com/iotaledger/iota.go/v4 v4.0.0-20230921110244-f4f25eb27e05 h1:arct4Q+cCFs6xaUS6lYt8hd1NFT+w1L5qoXGPC5ZYtU=
github.com/iotaledger/iota.go/v4 v4.0.0-20230921110244-f4f25eb27e05/go.mod h1:DWCa+mXRTGWBV0EHVuvToUxAEcICe2Pab9hBlxBamKo=
github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY=
github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
3 changes: 1 addition & 2 deletions pkg/model/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/serializer/v2/serix"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

type Block struct {
Expand Down Expand Up @@ -53,7 +52,7 @@ func BlockFromIDAndBytes(blockID iotago.BlockID, data []byte, api iotago.API, op
return newBlock(blockID, protocolBlock, data, api)
}

func BlockFromBytes(data []byte, apiProvider api.Provider, opts ...serix.Option) (*Block, error) {
func BlockFromBytes(data []byte, apiProvider iotago.APIProvider, opts ...serix.Option) (*Block, error) {
version, _, err := iotago.VersionFromBytes(data)
if err != nil {
return nil, ierrors.Wrap(err, "failed to determine version")
Expand Down
9 changes: 4 additions & 5 deletions pkg/model/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/iotaledger/hive.go/serializer/v2/serix"
"github.com/iotaledger/hive.go/stringify"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

type Commitment struct {
Expand All @@ -23,7 +22,7 @@ type Commitment struct {

func NewEmptyCommitment(api iotago.API) *Commitment {
emptyCommitment := iotago.NewEmptyCommitment(api.ProtocolParameters().Version())
emptyCommitment.RMC = api.ProtocolParameters().CongestionControlParameters().RMCMin
emptyCommitment.ReferenceManaCost = api.ProtocolParameters().CongestionControlParameters().MinReferenceManaCost

return lo.PanicOnErr(CommitmentFromCommitment(emptyCommitment, api))
}
Expand Down Expand Up @@ -51,7 +50,7 @@ func CommitmentFromCommitment(iotaCommitment *iotago.Commitment, api iotago.API,
return newCommitment(commitmentID, iotaCommitment, data, api)
}

func CommitmentFromBytes(data []byte, apiProvider api.Provider, opts ...serix.Option) (*Commitment, error) {
func CommitmentFromBytes(data []byte, apiProvider iotago.APIProvider, opts ...serix.Option) (*Commitment, error) {
version, _, err := iotago.VersionFromBytes(data)
if err != nil {
return nil, ierrors.Wrap(err, "failed to determine version")
Expand Down Expand Up @@ -83,8 +82,8 @@ func (c *Commitment) Index() iotago.SlotIndex {
return c.Commitment().Index
}

func (c *Commitment) PrevID() iotago.CommitmentID {
return c.Commitment().PrevID
func (c *Commitment) PreviousCommitmentID() iotago.CommitmentID {
return c.Commitment().PreviousCommitmentID
}

func (c *Commitment) RootsID() iotago.Identifier {
Expand Down
16 changes: 3 additions & 13 deletions pkg/network/protocols/core/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import (
"github.com/iotaledger/iota-core/pkg/network"
nwmodels "github.com/iotaledger/iota-core/pkg/network/protocols/core/models"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
"github.com/iotaledger/iota.go/v4/merklehasher"
)

type Protocol struct {
Events *Events

apiProvider api.Provider
apiProvider iotago.APIProvider

network network.Endpoint
workerPool *workerpool.WorkerPool
Expand All @@ -38,7 +37,7 @@ type Protocol struct {
requestedBlockHashesMutex syncutils.Mutex
}

func NewProtocol(network network.Endpoint, workerPool *workerpool.WorkerPool, apiProvider api.Provider, opts ...options.Option[Protocol]) (protocol *Protocol) {
func NewProtocol(network network.Endpoint, workerPool *workerpool.WorkerPool, apiProvider iotago.APIProvider, opts ...options.Option[Protocol]) (protocol *Protocol) {
return options.Apply(&Protocol{
Events: NewEvents(),

Expand Down Expand Up @@ -212,16 +211,7 @@ func (p *Protocol) onAttestations(commitmentBytes []byte, attestationsBytes []by
readOffset := 4
attestations := make([]*iotago.Attestation, attestationCount)
for i := uint32(0); i < attestationCount; i++ {
version := iotago.Version(attestationsBytes[readOffset])
apiForVersion, err := p.apiProvider.APIForVersion(version)
if err != nil {
p.Events.Error.Trigger(ierrors.Wrapf(err, "failed to deserialize attestations for commitment %s", cm.ID()), id)

return
}

attestation := new(iotago.Attestation)
consumed, err := apiForVersion.Decode(attestationsBytes[readOffset:], attestation, serix.WithValidation())
attestation, consumed, err := iotago.AttestationFromBytes(p.apiProvider)(attestationsBytes[readOffset:])
if err != nil {
p.Events.Error.Trigger(ierrors.Wrap(err, "failed to deserialize attestations"), id)

Expand Down
14 changes: 7 additions & 7 deletions pkg/protocol/chainmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (m *Manager) Commitments(id iotago.CommitmentID, amount int) (commitments [

commitments[i] = currentCommitment

id = currentCommitment.Commitment().PrevID()
id = currentCommitment.Commitment().PreviousCommitmentID()
}

return
Expand Down Expand Up @@ -237,8 +237,8 @@ func (m *Manager) SwitchMainChain(head iotago.CommitmentID) error {
func (m *Manager) processCommitment(commitment *model.Commitment) (wasForked bool, isSolid bool, chainCommitment *ChainCommitment) {
// Lock access to the parent commitment. We need to lock this first as we are trying to update children later within this function.
// Failure to do so, leads to a deadlock, where a child is locked and tries to lock its parent, which is locked by the parent which tries to lock the child.
m.commitmentEntityMutex.Lock(commitment.PrevID())
defer m.commitmentEntityMutex.Unlock(commitment.PrevID())
m.commitmentEntityMutex.Lock(commitment.PreviousCommitmentID())
defer m.commitmentEntityMutex.Unlock(commitment.PreviousCommitmentID())

// Lock access to the chainCommitment so no children are added while we are propagating solidity
m.commitmentEntityMutex.Lock(commitment.ID())
Expand Down Expand Up @@ -356,7 +356,7 @@ func (m *Manager) forkingPointAgainstMainChain(commitment *ChainCommitment) (*Ch
for chain := commitment.Chain(); chain != m.rootCommitment.Chain(); chain = commitment.Chain() {
forkingCommitment = chain.ForkingPoint

if commitment, _ = m.Commitment(forkingCommitment.Commitment().PrevID()); commitment == nil {
if commitment, _ = m.Commitment(forkingCommitment.Commitment().PreviousCommitmentID()); commitment == nil {
return nil, ierrors.Wrapf(ErrCommitmentUnknown, "unknown parent of solid commitment %s", forkingCommitment.Commitment().ID())
}
}
Expand All @@ -365,7 +365,7 @@ func (m *Manager) forkingPointAgainstMainChain(commitment *ChainCommitment) (*Ch
}

func (m *Manager) registerCommitment(commitment *model.Commitment) (isNew bool, isSolid bool, wasForked bool, chainCommitment *ChainCommitment) {
parentCommitment, commitmentCreated := m.getOrCreateCommitment(commitment.PrevID())
parentCommitment, commitmentCreated := m.getOrCreateCommitment(commitment.PreviousCommitmentID())
if commitmentCreated {
m.commitmentRequester.StartTicker(parentCommitment.ID())
}
Expand Down Expand Up @@ -398,7 +398,7 @@ func (m *Manager) switchMainChainToCommitment(commitment *ChainCommitment) error
return nil
}

parentCommitment, _ := m.Commitment(forkingPoint.Commitment().PrevID())
parentCommitment, _ := m.Commitment(forkingPoint.Commitment().PreviousCommitmentID())
if parentCommitment == nil {
return ierrors.Wrapf(ErrCommitmentUnknown, "unknown parent of solid commitment %s", forkingPoint.ID())
}
Expand All @@ -408,7 +408,7 @@ func (m *Manager) switchMainChainToCommitment(commitment *ChainCommitment) error

// For each forking point coming out of the main chain we need to reorg the children
for fp := commitment.Chain().ForkingPoint; ; {
fpParent, _ := m.Commitment(fp.Commitment().PrevID())
fpParent, _ := m.Commitment(fp.Commitment().PreviousCommitmentID())

mainChild := fpParent.mainChild()
newChildChain := NewChain(mainChild)
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/chainmanager/testframework.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (t *TestFramework) SlotCommitmentRoot(alias string) iotago.Identifier {
}

func (t *TestFramework) PrevSlotCommitment(alias string) iotago.CommitmentID {
return t.commitment(alias).PrevID()
return t.commitment(alias).PreviousCommitmentID()
}

func (t *TestFramework) AssertChainIsAlias(chain *Chain, alias string) {
Expand Down
11 changes: 3 additions & 8 deletions pkg/protocol/commitment_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,8 @@ func (c *CommitmentVerifier) verifyAttestations(attestations []*iotago.Attestati
return nil, 0, ierrors.Errorf("only ed25519 signatures supported, got %s", att.Signature.Type())
}

api, err := c.engine.APIForVersion(att.ProtocolVersion)
if err != nil {
return nil, 0, ierrors.Wrap(err, "error determining API for attestation")
}

// 2. Verify the signature of the attestation.
if valid, err := att.VerifySignature(api); !valid {
if valid, err := att.VerifySignature(); !valid {
if err != nil {
return nil, 0, ierrors.Wrap(err, "error validating attestation signature")
}
Expand All @@ -154,7 +149,7 @@ func (c *CommitmentVerifier) verifyAttestations(attestations []*iotago.Attestati
}

// TODO: this might differ if we have a Accounts with changing weights depending on the SlotIndex/epoch
attestationBlockID, err := att.BlockID(api)
attestationBlockID, err := att.BlockID()
if err != nil {
return nil, 0, ierrors.Wrap(err, "error calculating blockID from attestation")
}
Expand All @@ -164,7 +159,7 @@ func (c *CommitmentVerifier) verifyAttestations(attestations []*iotago.Attestati

visitedIdentities.Add(att.IssuerID)

blockID, err := att.BlockID(api)
blockID, err := att.BlockID()
if err != nil {
return nil, 0, ierrors.Wrap(err, "error calculating blockID from attestation")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocol/engine/accounts/accountsledger/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger"
"github.com/iotaledger/iota-core/pkg/storage/prunable/slotstore"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

// Manager is a Block Issuer Credits module responsible for tracking block issuance credit balances.
type Manager struct {
apiProvider api.Provider
apiProvider iotago.APIProvider
// blockBurns keep tracks of the block issues up to the LatestCommittedSlot. They are used to deduct the burned
// amount from the account's credits upon slot commitment.
blockBurns *shrinkingmap.ShrinkingMap[iotago.SlotIndex, ds.Set[iotago.BlockID]]
Expand Down Expand Up @@ -51,7 +50,7 @@ type Manager struct {
}

func New(
apiProvider api.Provider,
apiProvider iotago.APIProvider,
blockFunc func(id iotago.BlockID) (*blocks.Block, bool),
slotDiffFunc func(iotago.SlotIndex) (*slotstore.AccountDiffs, error),
accountsStore kvstore.KVStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
type TestSuite struct {
T *testing.T

apiProvider api.Provider
apiProvider iotago.APIProvider

accounts map[string]iotago.AccountID
blockIssuerKeys map[string]iotago.BlockIssuerKey
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocol/engine/accounts/mana/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/accounts"
"github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

// Manager is used to access stored and potential mana of an account in order.
// For stored Mana added to account, or stored/potential Mana spent, we will update on commitment.
// For potential Mana updates and decay, we update on demand if the Mana vector is accessed (by the scheduler).
type Manager struct {
apiProvider api.Provider
apiProvider iotago.APIProvider

manaVectorCache *cache.Cache[iotago.AccountID, *accounts.Mana]

Expand All @@ -28,7 +27,7 @@ type Manager struct {
module.Module
}

func NewManager(apiProvider api.Provider, accountOutputResolveFunc func(iotago.AccountID, iotago.SlotIndex) (*utxoledger.Output, error)) *Manager {
func NewManager(apiProvider iotago.APIProvider, accountOutputResolveFunc func(iotago.AccountID, iotago.SlotIndex) (*utxoledger.Output, error)) *Manager {
return &Manager{
apiProvider: apiProvider,
accountOutputResolveFunc: accountOutputResolveFunc,
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocol/engine/attestation/slotattestation/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/attestation"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

const (
Expand Down Expand Up @@ -61,7 +60,7 @@ type Manager struct {

commitmentMutex syncutils.RWMutex

apiProvider api.Provider
apiProvider iotago.APIProvider

module.Module
}
Expand All @@ -85,7 +84,7 @@ func NewManager(
lastCumulativeWeight uint64,
bucketedStorage func(index iotago.SlotIndex) (kvstore.KVStore, error),
committeeFunc func(index iotago.SlotIndex) *account.SeatedAccounts,
apiProvider api.Provider,
apiProvider iotago.APIProvider,
) *Manager {
m := &Manager{
lastCommittedSlot: lastCommittedSlot,
Expand Down
13 changes: 2 additions & 11 deletions pkg/protocol/engine/attestation/slotattestation/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,10 @@ func (m *Manager) attestationsForSlot(index iotago.SlotIndex) (ads.Map[iotago.Ac
return nil, ierrors.Wrapf(err, "failed to get extended realm for attestations of slot %d", index)
}

api := m.apiProvider.APIForSlot(index)

return ads.NewMap(attestationsStorage,
iotago.Identifier.Bytes,
iotago.IdentifierFromBytes,
func(v *iotago.Attestation) ([]byte, error) {
return api.Encode(v)
},
func(bytes []byte) (object *iotago.Attestation, consumed int, err error) {
attestation := new(iotago.Attestation)
consumed, err = api.Decode(bytes, attestation)

return attestation, consumed, err
},
(*iotago.Attestation).Bytes,
iotago.AttestationFromBytes(m.apiProvider),
), nil
}
Loading

0 comments on commit cec44e5

Please sign in to comment.