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

varLocalView redesigned. #3230

Draft
wants to merge 8 commits into
base: iota2.0
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cluster-data/
dist/
.idea/
.vscode/
.tlacache/
*.bat
*.bak
Cargo.lock
Expand Down
66 changes: 37 additions & 29 deletions packages/chain/chainmanager/chain_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import (
"github.com/iotaledger/hive.go/log"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/wasp/packages/chain/cmt_log"
"github.com/iotaledger/wasp/packages/chain/cons"
"github.com/iotaledger/wasp/packages/cryptolib"
"github.com/iotaledger/wasp/packages/gpa"
"github.com/iotaledger/wasp/packages/isc"
Expand All @@ -102,10 +103,17 @@ func (o *Output) LatestActiveAnchorOutput() *isc.ChainOutputs {
if o.cmi.needConsensus == nil {
return nil
}
return o.cmi.needConsensus.BaseAnchorOutput
return o.cmi.needConsensus.ConsensusInput.BaseCO()
}
func (o *Output) LatestConfirmedAnchorOutput() *isc.ChainOutputs { return o.cmi.latestConfirmedAO }
func (o *Output) NeedConsensus() *NeedConsensus { return o.cmi.needConsensus }

func (o *Output) LatestConfirmedAnchorOutput() *isc.ChainOutputs {
return o.cmi.latestConfirmedAO
}

func (o *Output) NeedConsensus() *NeedConsensus {
return o.cmi.needConsensus
}

func (o *Output) NeedPublishTX() *shrinkingmap.ShrinkingMap[iotago.TransactionID, *NeedPublishTX] {
return o.cmi.needPublishTX
}
Expand All @@ -120,22 +128,22 @@ func (o *Output) String() string {
}

type NeedConsensus struct {
CommitteeAddr iotago.Ed25519Address
LogIndex cmt_log.LogIndex
DKShare tcrypto.DKShare
BaseAnchorOutput *isc.ChainOutputs
CommitteeAddr iotago.Ed25519Address
LogIndex cmt_log.LogIndex
DKShare tcrypto.DKShare
ConsensusInput cons.Input
}

func (nc *NeedConsensus) IsFor(output *cmt_log.Output) bool {
return output.GetLogIndex() == nc.LogIndex && output.GetBaseAnchorOutput().Equals(nc.BaseAnchorOutput)
return output.GetLogIndex() == nc.LogIndex
}

func (nc *NeedConsensus) String() string {
return fmt.Sprintf(
"{chainMgr.NeedConsensus, CommitteeAddr=%v, LogIndex=%v, BaseAnchorOutput=%v}",
"{chainMgr.NeedConsensus, CommitteeAddr=%v, LogIndex=%v, ConsensusInput=%v}",
nc.CommitteeAddr.String(),
nc.LogIndex,
nc.BaseAnchorOutput,
nc.ConsensusInput,
)
}

Expand Down Expand Up @@ -278,10 +286,10 @@ func (cmi *chainMgrImpl) handleInputAnchorOutputConfirmed(input *inputAnchorOutp
cmi.log.LogDebugf("handleInputAnchorOutputConfirmed: %+v", input)
//
// > Set LatestConfirmedAO <- ConfirmedAO
vsaTip, vsaUpdated := cmi.varAccessNodeState.BlockConfirmed(input.anchorOutput)
cmi.latestConfirmedAO = input.anchorOutput
vsaTip, vsaUpdated := cmi.varAccessNodeState.BlockConfirmed(input.confirmedOutputs) // TODO:
cmi.latestConfirmedAO = input.confirmedOutputs
msgs := gpa.NoMessages()
committeeAddr := input.anchorOutput.AnchorOutput.StateController().(*iotago.Ed25519Address)
committeeAddr := input.confirmedOutputs.AnchorOutput.StateController().(*iotago.Ed25519Address)
committeeLog, err := cmi.ensureCmtLog(*committeeAddr)
if errors.Is(err, ErrNotInCommittee) {
// > IF this node is in the committee THEN ... ELSE
Expand All @@ -299,7 +307,7 @@ func (cmi *chainMgrImpl) handleInputAnchorOutputConfirmed(input *inputAnchorOutp
cmi.log.LogDebugf("⊢ going to track %v as an access node on confirmed block.", vsaTip)
cmi.trackActiveStateCB(vsaTip)
}
cmi.log.LogDebugf("This node is not in the committee for anchorOutput: %v", input.anchorOutput)
cmi.log.LogDebugf("This node is not in the committee for anchorOutput: %v", input.confirmedOutputs)
return msgs
}
if err != nil {
Expand All @@ -310,7 +318,7 @@ func (cmi *chainMgrImpl) handleInputAnchorOutputConfirmed(input *inputAnchorOutp
// > Pass it to the corresponding CmtLog; HandleCmtLogOutput.
msgs.AddAll(cmi.handleCmtLogOutput(
committeeLog,
committeeLog.gpaInstance.Input(cmt_log.NewInputAnchorOutputConfirmed(input.anchorOutput)),
committeeLog.gpaInstance.Input(cmt_log.NewInputAnchorOutputConfirmed(input.confirmedOutputs)),
))
return msgs
}
Expand Down Expand Up @@ -350,10 +358,10 @@ func (cmi *chainMgrImpl) handleInputConsensusOutputDone(input *inputConsensusOut
// > IF ConsensusOutput.BaseAO == NeedConsensus THEN
// > Add ConsensusOutput.TX to NeedPublishTX
if true { // TODO: Reconsider this condition. Several recent consensus instances should be published, if we run consensus instances in parallel.
txID := input.consensusResult.NextAnchorOutput.AnchorOutputID.TransactionID()
if !cmi.needPublishTX.Has(txID) && input.consensusResult.Block != nil {
txID := input.consensusResult.ProducedChainOutputs().AnchorOutputID.TransactionID()
if !cmi.needPublishTX.Has(txID) && input.consensusResult.ProducedStateBlock() != nil {
// Inform the access nodes on new block produced.
block := input.consensusResult.Block
block := input.consensusResult.ProducedStateBlock()
activeAccessNodes, activeCommitteeNodes := cmi.activeNodesCB()
cmi.log.LogDebugf(
"Sending MsgBlockProduced (stateIndex=%v, l1Commitment=%v, txID=%v) to access nodes: %v except committeeNodes %v",
Expand All @@ -363,22 +371,22 @@ func (cmi *chainMgrImpl) handleInputConsensusOutputDone(input *inputConsensusOut
if lo.Contains(activeCommitteeNodes, activeAccessNodes[i]) {
continue
}
msgs.Add(NewMsgBlockProduced(cmi.nodeIDFromPubKey(activeAccessNodes[i]), input.consensusResult.Transaction, block))
msgs.Add(NewMsgBlockProduced(cmi.nodeIDFromPubKey(activeAccessNodes[i]), input.consensusResult.ProducedTransaction(), block))
}
}
cmi.needPublishTX.Set(txID, &NeedPublishTX{
CommitteeAddr: input.committeeAddr,
LogIndex: input.logIndex,
TxID: txID,
Tx: input.consensusResult.Transaction,
BaseAnchorOutputID: input.consensusResult.BaseAnchorOutput,
NextAnchorOutput: input.consensusResult.NextAnchorOutput,
Tx: input.consensusResult.ProducedTransaction(),
BaseAnchorOutputID: input.consensusResult.ConsumedAnchorOutputID(),
NextAnchorOutput: input.consensusResult.ProducedChainOutputs(),
})
}
//
// > Forward the message to the corresponding CmtLog; HandleCmtLogOutput.
msgs.AddAll(cmi.withCmtLog(input.committeeAddr, func(cl gpa.GPA) gpa.OutMessages {
return cl.Input(cmt_log.NewInputConsensusOutputDone(input.logIndex, input.proposedBaseAO, input.consensusResult.BaseAnchorOutput, input.consensusResult.NextAnchorOutput))
return cl.Input(cmt_log.NewInputConsensusOutputDone(input.logIndex, input.consensusResult))
}))
return msgs
}
Expand All @@ -387,7 +395,7 @@ func (cmi *chainMgrImpl) handleInputConsensusOutputDone(input *inputConsensusOut
// > Forward the message to the corresponding CmtLog; HandleCmtLogOutput.
func (cmi *chainMgrImpl) handleInputConsensusOutputSkip(input *inputConsensusOutputSkip) gpa.OutMessages {
return cmi.withCmtLog(input.committeeAddr, func(cl gpa.GPA) gpa.OutMessages {
return cl.Input(cmt_log.NewInputConsensusOutputSkip(input.logIndex, input.proposedBaseAO))
return cl.Input(cmt_log.NewInputConsensusOutputSkip(input.logIndex))
})
}

Expand Down Expand Up @@ -494,7 +502,7 @@ func (cmi *chainMgrImpl) ensureNeedConsensus(cli *cmtLogInst, outputUntyped gpa.
// Not changed, keep it.
return
}
committeeAddress := output.GetBaseAnchorOutput().AnchorOutput.StateController()
committeeAddress := output.ConsensusInput().BaseCO().AnchorOutput.StateController() // TODO: BaseCO can be nil.
dkShare, err := cmi.dkShareRegistryProvider.LoadDKShare(committeeAddress)
if errors.Is(err, tcrypto.ErrDKShareNotFound) {
// Rotated to other nodes, so we don't need to start the next consensus.
Expand All @@ -505,10 +513,10 @@ func (cmi *chainMgrImpl) ensureNeedConsensus(cli *cmtLogInst, outputUntyped gpa.
panic(fmt.Errorf("ensureNeedConsensus cannot load DKShare for %v: %w", committeeAddress, err))
}
cmi.needConsensus = &NeedConsensus{
CommitteeAddr: cli.committeeAddr,
LogIndex: output.GetLogIndex(),
DKShare: dkShare,
BaseAnchorOutput: output.GetBaseAnchorOutput(),
CommitteeAddr: cli.committeeAddr,
LogIndex: output.GetLogIndex(),
DKShare: dkShare,
ConsensusInput: output.ConsensusInput(),
}
}

Expand Down
12 changes: 6 additions & 6 deletions packages/chain/chainmanager/chain_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func testChainMgrBasic(t *testing.T, n, f int) {
out := n.Output().(*chainmanager.Output)
require.Equal(t, 0, out.NeedPublishTX().Size())
require.NotNil(t, out.NeedConsensus())
require.Equal(t, originAO, out.NeedConsensus().BaseAnchorOutput)
require.Equal(t, originAO, out.NeedConsensus().ConsensusInput)
require.Equal(t, uint32(1), out.NeedConsensus().LogIndex.AsUint32())
require.Equal(t, cmtPubKeyA, &out.NeedConsensus().CommitteeAddr)
}
Expand All @@ -136,7 +136,7 @@ func testChainMgrBasic(t *testing.T, n, f int) {
&cons.Result{
Transaction: step2TX,
Block: block0,
BaseAnchorOutput: consReq.BaseAnchorOutput.AnchorOutputID,
BaseAnchorOutput: consReq.ConsensusInput.AnchorOutputID,
NextAnchorOutput: step2AO,
},
))
Expand All @@ -160,7 +160,7 @@ func testChainMgrBasic(t *testing.T, n, f int) {
return &tx.CommitteeAddr
}())
require.NotNil(t, out.NeedConsensus())
require.Equal(t, step2AO, out.NeedConsensus().BaseAnchorOutput)
require.Equal(t, step2AO, out.NeedConsensus().ConsensusInput)
require.Equal(t, uint32(2), out.NeedConsensus().LogIndex.AsUint32())
require.Equal(t, cmtPubKeyA, &out.NeedConsensus().CommitteeAddr)
}
Expand All @@ -176,7 +176,7 @@ func testChainMgrBasic(t *testing.T, n, f int) {
out := n.Output().(*chainmanager.Output)
require.Equal(t, 0, out.NeedPublishTX().Size())
require.NotNil(t, out.NeedConsensus())
require.Equal(t, step2AO, out.NeedConsensus().BaseAnchorOutput)
require.Equal(t, step2AO, out.NeedConsensus().ConsensusInput)
require.Equal(t, uint32(2), out.NeedConsensus().LogIndex.AsUint32())
require.Equal(t, cmtPubKeyA, &out.NeedConsensus().CommitteeAddr)
}
Expand All @@ -191,7 +191,7 @@ func testChainMgrBasic(t *testing.T, n, f int) {
out := n.Output().(*chainmanager.Output)
require.Equal(t, 0, out.NeedPublishTX().Size())
require.NotNil(t, out.NeedConsensus())
require.Equal(t, step2AO, out.NeedConsensus().BaseAnchorOutput)
require.Equal(t, step2AO, out.NeedConsensus().ConsensusInput)
require.Equal(t, uint32(2), out.NeedConsensus().LogIndex.AsUint32())
require.Equal(t, cmtPubKeyA, &out.NeedConsensus().CommitteeAddr)
}
Expand All @@ -207,7 +207,7 @@ func testChainMgrBasic(t *testing.T, n, f int) {
out := n.Output().(*chainmanager.Output)
require.Equal(t, 0, out.NeedPublishTX().Size())
require.NotNil(t, out.NeedConsensus())
require.Equal(t, rotateAO, out.NeedConsensus().BaseAnchorOutput)
require.Equal(t, rotateAO, out.NeedConsensus().ConsensusInput)
require.Equal(t, uint32(1), out.NeedConsensus().LogIndex.AsUint32())
require.Equal(t, cmtPubKeyB, &out.NeedConsensus().CommitteeAddr)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/chain/chainmanager/input_alias_output_received.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
)

type inputAnchorOutputConfirmed struct {
anchorOutput *isc.ChainOutputs
confirmedOutputs *isc.ChainOutputs
}

func NewInputAnchorOutputConfirmed(anchorOutput *isc.ChainOutputs) gpa.Input {
func NewInputAnchorOutputConfirmed(confirmedOutputs *isc.ChainOutputs) gpa.Input {
return &inputAnchorOutputConfirmed{
anchorOutput: anchorOutput,
confirmedOutputs: confirmedOutputs,
}
}

func (inp *inputAnchorOutputConfirmed) String() string {
return fmt.Sprintf("{chainMgr.inputAnchorOutputConfirmed, %v}", inp.anchorOutput)
return fmt.Sprintf("{chainMgr.inputAnchorOutputConfirmed, %v}", inp.confirmedOutputs)
}
6 changes: 1 addition & 5 deletions packages/chain/chainmanager/input_consensus_output_done.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,26 @@ import (
type inputConsensusOutputDone struct {
committeeAddr iotago.Ed25519Address
logIndex cmt_log.LogIndex
proposedBaseAO iotago.OutputID
consensusResult *cons.Result
}

func NewInputConsensusOutputDone(
committeeAddr iotago.Ed25519Address,
logIndex cmt_log.LogIndex,
proposedBaseAO iotago.OutputID,
consensusResult *cons.Result,
) gpa.Input {
return &inputConsensusOutputDone{
committeeAddr: committeeAddr,
logIndex: logIndex,
proposedBaseAO: proposedBaseAO,
consensusResult: consensusResult,
}
}

func (inp *inputConsensusOutputDone) String() string {
return fmt.Sprintf(
"{chainMgr.inputConsensusOutputDone, committeeAddr=%v, logIndex=%v, proposedBaseAO=%v, consensusResult=%v}",
"{chainMgr.inputConsensusOutputDone, committeeAddr=%v, logIndex=%v, consensusResult=%v}",
inp.committeeAddr.String(),
inp.logIndex,
inp.proposedBaseAO.ToHex(),
inp.consensusResult,
)
}
14 changes: 5 additions & 9 deletions packages/chain/chainmanager/input_consensus_output_skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,24 @@ import (
)

type inputConsensusOutputSkip struct {
committeeAddr iotago.Ed25519Address
logIndex cmt_log.LogIndex
proposedBaseAO iotago.OutputID
committeeAddr iotago.Ed25519Address
logIndex cmt_log.LogIndex
}

func NewInputConsensusOutputSkip(
committeeAddr iotago.Ed25519Address,
logIndex cmt_log.LogIndex,
proposedBaseAO iotago.OutputID,
) gpa.Input {
return &inputConsensusOutputSkip{
committeeAddr: committeeAddr,
logIndex: logIndex,
proposedBaseAO: proposedBaseAO,
committeeAddr: committeeAddr,
logIndex: logIndex,
}
}

func (inp *inputConsensusOutputSkip) String() string {
return fmt.Sprintf(
"{chainMgr.inputConsensusOutputSkip, committeeAddr=%v, logIndex=%v, proposedBaseAO=%v}",
"{chainMgr.inputConsensusOutputSkip, committeeAddr=%v, logIndex=%v}",
inp.committeeAddr.String(),
inp.logIndex,
inp.proposedBaseAO.ToHex(),
)
}
Loading