Skip to content
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/holiman/uint256 v1.3.2
github.com/iotaledger/bcs-go v0.0.0-20250716100925-71f848cac593
github.com/iotaledger/bcs-go v0.0.0-20251107161402-980e31f7d5f7
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7
github.com/iotaledger/hive.go/app v0.0.0-20251001162450-d572d7955f11
github.com/iotaledger/hive.go/constraints v0.0.0-20251001162450-d572d7955f11
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJ
github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
github.com/iotaledger/bcs-go v0.0.0-20250716100925-71f848cac593 h1:gfl7sPlhXPd+9YBb3V+C5U8bRvOozsOaubKwgQZWZ1w=
github.com/iotaledger/bcs-go v0.0.0-20250716100925-71f848cac593/go.mod h1:yTxBDTSAbTPf9Xz0JAiBTVRM9RlJCCZd6amEA85L6ac=
github.com/iotaledger/bcs-go v0.0.0-20251107153435-2b6e4bbdcb0a h1:XG1WN7nlq0PQppuCEIZPeeFW6JPh1ijKYt1PLKX6p44=
github.com/iotaledger/bcs-go v0.0.0-20251107153435-2b6e4bbdcb0a/go.mod h1:yTxBDTSAbTPf9Xz0JAiBTVRM9RlJCCZd6amEA85L6ac=
github.com/iotaledger/bcs-go v0.0.0-20251107161402-980e31f7d5f7 h1:8hBuGWWZOyyfpeo3v7FFVig8kA8xQN9kCjzwyTB8YX8=
github.com/iotaledger/bcs-go v0.0.0-20251107161402-980e31f7d5f7/go.mod h1:yTxBDTSAbTPf9Xz0JAiBTVRM9RlJCCZd6amEA85L6ac=
github.com/iotaledger/go-ethereum v1.16.2-wasp h1:cjVwedrUNXnFor77tDJOlTN8NY+SxxW68vbq3tmhMhs=
github.com/iotaledger/go-ethereum v1.16.2-wasp/go.mod h1:X5CIOyo8SuK1Q5GnaEizQVLHT/DfsiGWuNeVdQcEMNA=
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 h1:dTrD7X2PTNgli6EbS4tV9qu3QAm/kBU3XaYZV2xdzys=
Expand Down
5 changes: 5 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+h
github.com/influxdata/influxdb-client-go/v2 v2.4.0/go.mod h1:vLNHdxTJkIf2mSLvGrpj8TCcISApPoXkaxP8g9uRlW8=
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/iotaledger/hive.go/constraints v0.0.0-20240520064018-c635e5900894/go.mod h1:JF7jjkL6tSUOXm23SWadBzBrl7eJk1DQRLc/fNoVZ+o=
github.com/iotaledger/hive.go/kvstore v0.0.0-20230829151000-a4416d2e9c93/go.mod h1:DeP4JF4N995LteD0+/o7NsW1bO5IXURIJ27A69Ca5+Y=
github.com/iotaledger/iota.go v1.0.0/go.mod h1:RiKYwDyY7aCD1L0YRzHSjOsJ5mUR9yvQpvhZncNcGQI=
github.com/ipfs/go-datastore v0.8.2/go.mod h1:W+pI1NsUsz3tcsAACMtfC+IZdnQTnC/7VfPoJBQuts0=
Expand Down Expand Up @@ -240,6 +241,7 @@ go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -249,6 +251,8 @@ golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand All @@ -259,6 +263,7 @@ golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
46 changes: 25 additions & 21 deletions packages/chain/chainmanager/chain_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func (npt *NeedPublishTX) String() string {
type committeeLogInst struct {
committeeAddr cryptolib.Address
dkShare tcrypto.DKShare
gpaInstance gpa.GPA
pendingMsgs []gpa.Message
gpaInstance *committeelog.CommitteeLog
}

type ChainMgr struct {
Expand Down Expand Up @@ -293,8 +293,8 @@ func (cmi *ChainMgr) Input(input gpa.Input) gpa.OutMessages {
// Message implements the gpa.GPA interface.
func (cmi *ChainMgr) Message(msg gpa.Message) gpa.OutMessages {
switch msg := msg.(type) {
case *msgCommitteeLog:
return cmi.handleMsgCommitteeLog(msg)
case *msgNextLogIndex:
return cmi.handleMsgNextLogIndex(msg)
case *msgBlockProduced:
return cmi.handleMsgBlockProduced(msg)
}
Expand Down Expand Up @@ -366,13 +366,13 @@ func (cmi *ChainMgr) handleInputChainTxPublishResult(input *inputChainTxPublishR
if input.confirmed {
// > If result.confirmed = false THEN ... ELSE
// > NOP // Anchor has to be received as Confirmed Anchor. // TODO: Not true, anymore.
return cmi.withCommitteeLog(input.committeeAddr, func(cl gpa.GPA) gpa.OutMessages {
return cmi.withCommitteeLog(input.committeeAddr, func(cl *committeelog.CommitteeLog) committeelog.OutMessages {
return cl.Input(committeelog.NewInputConsensusOutputConfirmed(input.anchor, input.logIndex))
})
}
// > If result.confirmed = false THEN
// > Forward it to ChainMgr; HandleCommitteeLogOutput.
return cmi.withCommitteeLog(input.committeeAddr, func(cl gpa.GPA) gpa.OutMessages {
return cmi.withCommitteeLog(input.committeeAddr, func(cl *committeelog.CommitteeLog) committeelog.OutMessages {
return cl.Input(committeelog.NewInputConsensusOutputRejected(input.anchor, input.logIndex))
})
}
Expand Down Expand Up @@ -433,7 +433,7 @@ func (cmi *ChainMgr) handleInputConsensusOutputDone(input *inputConsensusOutputD
// > UPON Reception of Consensus Output/SKIP:
// > Forward the message to the corresponding CommitteeLog; HandleCommitteeLogOutput.
func (cmi *ChainMgr) handleInputConsensusOutputSkip(input *inputConsensusOutputSkip) gpa.OutMessages {
return cmi.withCommitteeLog(input.committeeAddr, func(cl gpa.GPA) gpa.OutMessages {
return cmi.withCommitteeLog(input.committeeAddr, func(cl *committeelog.CommitteeLog) committeelog.OutMessages {
return cl.Input(committeelog.NewInputConsensusOutputSkip(input.logIndex))
})
}
Expand All @@ -442,24 +442,24 @@ func (cmi *ChainMgr) handleInputConsensusOutputSkip(input *inputConsensusOutputS
// > Forward the message to the corresponding CommitteeLog; HandleCommitteeLogOutput.
func (cmi *ChainMgr) handleInputConsensusTimeout(input *inputConsensusTimeout) gpa.OutMessages {
cmi.log.LogDebugf("handleInputConsensusTimeout: %+v", input)
return cmi.withCommitteeLog(input.committeeAddr, func(cl gpa.GPA) gpa.OutMessages {
return cmi.withCommitteeLog(input.committeeAddr, func(cl *committeelog.CommitteeLog) committeelog.OutMessages {
return cl.Input(committeelog.NewInputConsensusTimeout(input.logIndex))
})
}

func (cmi *ChainMgr) handleInputCanPropose() gpa.OutMessages {
cmi.log.LogDebugf("handleInputCanPropose")
return cmi.withAllCommitteeLogs(func(cl gpa.GPA) gpa.OutMessages {
return cmi.withAllCommitteeLogs(func(cl *committeelog.CommitteeLog) committeelog.OutMessages {
return cl.Input(committeelog.NewInputCanPropose())
})
}

// > UPON Reception of CommitteeLog.NextLI message:
// > Forward it to the corresponding CommitteeLog; HandleCommitteeLogOutput.
func (cmi *ChainMgr) handleMsgCommitteeLog(msg *msgCommitteeLog) gpa.OutMessages {
cmi.log.LogDebugf("handleMsgCommitteeLog: %+v", msg)
return cmi.withCommitteeLog(msg.committeeAddr, func(cl gpa.GPA) gpa.OutMessages {
return cl.Message(msg.wrapped)
func (cmi *ChainMgr) handleMsgNextLogIndex(msg *msgNextLogIndex) gpa.OutMessages {
cmi.log.LogDebugf("handleMsgNextLogIndex: %+v", msg)
return cmi.withCommitteeLog(msg.CommitteeAddr, func(cl *committeelog.CommitteeLog) committeelog.OutMessages {
return cl.HandleMsgNextLogIndex(&msg.MsgForCommitteeLog)
})
}

Expand Down Expand Up @@ -497,7 +497,7 @@ func (cmi *ChainMgr) handleMsgBlockProduced(msg *msgBlockProduced) gpa.OutMessag
// > Suspend(LatestActiveCmt)
// > Set LatestActiveCmt <- cmt
// > Set NeedConsensus <- output.NeedConsensus
func (cmi *ChainMgr) handleCommitteeLogOutput(cli *committeeLogInst, cliMsgs gpa.OutMessages) gpa.OutMessages {
func (cmi *ChainMgr) handleCommitteeLogOutput(cli *committeeLogInst, cliMsgs committeelog.OutMessages) gpa.OutMessages {
//
// > Wrap out messages.
msgs := gpa.NoMessages()
Expand Down Expand Up @@ -605,11 +605,16 @@ func (cmi *ChainMgr) StatusString() string { // TODO: Call it periodically. Show
////////////////////////////////////////////////////////////////////////////////
// Helper functions.

func (cmi *ChainMgr) wrapCommitteeLogMsgs(cli *committeeLogInst, outMsgs gpa.OutMessages) gpa.OutMessages {
func (cmi *ChainMgr) wrapCommitteeLogMsgs(cli *committeeLogInst, outMsgs committeelog.OutMessages) gpa.OutMessages {
wrappedMsgs := gpa.NoMessages()
outMsgs.MustIterate(func(msg gpa.Message) {
wrappedMsgs.Add(NewMsgCommitteeLog(cli.committeeAddr, msg))
})
if outMsgs == nil {
return wrappedMsgs
}

for _, msg := range outMsgs.NextLogIndex {
wrappedMsgs.Add(NewMsgNextLogIndex(cli.committeeAddr, msg))
}

return wrappedMsgs
}

Expand All @@ -623,7 +628,7 @@ func (cmi *ChainMgr) suspendCommittee(committeeAddr *cryptolib.Address) gpa.OutM
return nil
}

func (cmi *ChainMgr) withCommitteeLog(committeeAddr cryptolib.Address, handler func(cl gpa.GPA) gpa.OutMessages) gpa.OutMessages {
func (cmi *ChainMgr) withCommitteeLog(committeeAddr cryptolib.Address, handler func(cl *committeelog.CommitteeLog) committeelog.OutMessages) gpa.OutMessages {
cli, err := cmi.ensureCommitteeLog(committeeAddr)
if err != nil {
cmi.log.LogWarnf("cannot find committee: %v", committeeAddr)
Expand All @@ -632,7 +637,7 @@ func (cmi *ChainMgr) withCommitteeLog(committeeAddr cryptolib.Address, handler f
return gpa.NoMessages().AddAll(cmi.handleCommitteeLogOutput(cli, handler(cli.gpaInstance)))
}

func (cmi *ChainMgr) withAllCommitteeLogs(handler func(cl gpa.GPA) gpa.OutMessages) gpa.OutMessages {
func (cmi *ChainMgr) withAllCommitteeLogs(handler func(cl *committeelog.CommitteeLog) committeelog.OutMessages) gpa.OutMessages {
msgs := gpa.NoMessages()
for _, cli := range cmi.committeeLogs {
msgs.AddAll(cmi.handleCommitteeLogOutput(cli, handler(cli.gpaInstance)))
Expand Down Expand Up @@ -682,11 +687,10 @@ func (cmi *ChainMgr) ensureCommitteeLog(committeeAddr cryptolib.Address) (*commi
if err != nil {
return nil, fmt.Errorf("cannot create committeeLog for committeeAddress=%v: %w", committeeAddr, err)
}
clGPA := clInst.AsGPA()
cli := &committeeLogInst{
committeeAddr: committeeAddr,
dkShare: dkShare,
gpaInstance: clGPA,
gpaInstance: clInst,
pendingMsgs: []gpa.Message{},
}
cmi.committeeLogs[committeeAddr.Key()] = cli
Expand Down
14 changes: 3 additions & 11 deletions packages/chain/chainmanager/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@ package chainmanager

import (
"github.com/iotaledger/wasp/v2/packages/gpa"
"github.com/iotaledger/wasp/v2/packages/state"
)

const (
msgTypeCommitteeLog gpa.MessageType = iota
msgTypeMsgNextLogIndex gpa.MessageType = iota
msgTypeBlockProduced
)

func (cmi *ChainMgr) UnmarshalMessage(data []byte) (gpa.Message, error) {
return gpa.UnmarshalMessage(data, gpa.Mapper{
msgTypeCommitteeLog: func() gpa.Message { return new(msgCommitteeLog) },
msgTypeBlockProduced: func() gpa.Message {
msgBlock := new(msgBlockProduced)

// TODO: Validate if we ever have different block implementations.
msgBlock.block = state.NewBlock()

return msgBlock
},
msgTypeMsgNextLogIndex: func() gpa.Message { return new(msgNextLogIndex) },
msgTypeBlockProduced: func() gpa.Message { return new(msgBlockProduced) },
})
}
60 changes: 15 additions & 45 deletions packages/chain/chainmanager/msg_cmt_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,35 @@ package chainmanager
import (
"fmt"

bcs "github.com/iotaledger/bcs-go"
"github.com/iotaledger/wasp/v2/packages/chain/committeelog"
"github.com/iotaledger/wasp/v2/packages/cryptolib"
"github.com/iotaledger/wasp/v2/packages/gpa"
)

// gpa.Wrapper is not applicable here, because here the addressing
// is by CommitteeID, not by integer index.
type msgCommitteeLog struct {
committeeAddr cryptolib.Address
wrapped gpa.Message
type msgNextLogIndex struct {
CommitteeAddr cryptolib.Address
MsgForCommitteeLog committeelog.MsgNextLogIndex
}

var _ gpa.Message = new(msgCommitteeLog)

func NewMsgCommitteeLog(committeeAddr cryptolib.Address, wrapped gpa.Message) gpa.Message {
return &msgCommitteeLog{
committeeAddr: committeeAddr,
wrapped: wrapped,
func NewMsgNextLogIndex(committeeAddr cryptolib.Address, msg committeelog.MsgNextLogIndex) *msgNextLogIndex {
return &msgNextLogIndex{
CommitteeAddr: committeeAddr,
MsgForCommitteeLog: msg,
}
}

func (msg *msgCommitteeLog) MsgType() gpa.MessageType {
return msgTypeCommitteeLog
}

func (msg *msgCommitteeLog) String() string {
return fmt.Sprintf("{chainMgr.msgCommitteeLog, committeeAddr=%v, wrapped=%+v}", msg.committeeAddr.String(), msg.wrapped)
func (msg *msgNextLogIndex) MsgType() gpa.MessageType {
return msgTypeMsgNextLogIndex
}

func (msg *msgCommitteeLog) Recipient() gpa.NodeID {
return msg.wrapped.Recipient()
func (msg *msgNextLogIndex) String() string {
return fmt.Sprintf("{chainMgr.msgNextLogIndex, committeeAddr=%v, MsgNextLogIndex=%+v}", msg.CommitteeAddr.String(), msg.MsgForCommitteeLog)
}

func (msg *msgCommitteeLog) SetSender(sender gpa.NodeID) {
msg.wrapped.SetSender(sender)
func (msg *msgNextLogIndex) Recipient() gpa.NodeID {
return msg.MsgForCommitteeLog.Recipient()
}

func (msg *msgCommitteeLog) MarshalBCS(e *bcs.Encoder) error {
wrappedBytes, err := gpa.MarshalMessage(msg.wrapped)
if err != nil {
return fmt.Errorf("marshaling wrapped message: %w", err)
}

e.Encode(msg.committeeAddr)
e.Encode(wrappedBytes)

return nil
}

func (msg *msgCommitteeLog) UnmarshalBCS(d *bcs.Decoder) error {
d.Decode(&msg.committeeAddr)
wrappedBytes := bcs.Decode[[]byte](d)

var err error
msg.wrapped, err = committeelog.UnmarshalMessage(wrappedBytes)
if err != nil {
return fmt.Errorf("unmarshaling wrapped message: %w", err)
}

return nil
func (msg *msgNextLogIndex) SetSender(sender gpa.NodeID) {
msg.MsgForCommitteeLog.SetSender(sender)
}
8 changes: 4 additions & 4 deletions packages/chain/chainmanager/msg_cmt_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

func TestMsgCommitteeLogSerialization(t *testing.T) {
address := cryptolib.NewRandomAddress()
msg := &msgCommitteeLog{
msg := &msgNextLogIndex{
*address,
&committeelog.MsgNextLogIndex{
committeelog.MsgNextLogIndex{
BasicMessage: gpa.BasicMessage{},
NextLogIndex: committeelog.LogIndex(rand.Int31()),
PleaseRepeat: false,
Expand All @@ -23,9 +23,9 @@ func TestMsgCommitteeLogSerialization(t *testing.T) {

bcs.TestCodec(t, msg)

msg = &msgCommitteeLog{
msg = &msgNextLogIndex{
*cryptolib.TestAddress,
&committeelog.MsgNextLogIndex{
committeelog.MsgNextLogIndex{
BasicMessage: gpa.BasicMessage{},
NextLogIndex: committeelog.LogIndex(1234567890),
PleaseRepeat: false,
Expand Down
Loading
Loading