diff --git a/chain/consensus/mir/logger.go b/chain/consensus/mir/logger.go index ce45d105b..de0a70643 100644 --- a/chain/consensus/mir/logger.go +++ b/chain/consensus/mir/logger.go @@ -10,7 +10,7 @@ const managerLoggerName = "mir-manager" var _ mirlogging.Logger = &managerLogger{} -// mirLogger implements Mir's Log interface. +// managerLogger implements Mir's Log interface. type managerLogger struct { logger *ipfslogging.ZapEventLogger } @@ -23,20 +23,39 @@ func newManagerLogger() *managerLogger { // Log logs a message with additional context. func (l *managerLogger) Log(level mirlogging.LogLevel, text string, args ...interface{}) { + // Mir's LevelTrace is ignored. switch level { case mirlogging.LevelError: - l.logger.Errorw(text, "error", args) + l.logger.Errorw(text, args...) case mirlogging.LevelInfo: - l.logger.Infow(text, "info", args) + l.logger.Infow(text, args...) case mirlogging.LevelWarn: - l.logger.Warnw(text, "warn", args) + l.logger.Warnw(text, args...) case mirlogging.LevelDebug: - l.logger.Debugw(text, "debug", args) + l.logger.Debugw(text, args...) } } func (l *managerLogger) MinLevel() mirlogging.LogLevel { - return mirlogging.LevelDisable + level := ipfslogging.GetConfig().SubsystemLevels[managerLoggerName] + switch level { + case ipfslogging.LevelDebug: + return mirlogging.LevelDebug + case ipfslogging.LevelInfo: + return mirlogging.LevelInfo + case ipfslogging.LevelWarn: + return mirlogging.LevelWarn + case ipfslogging.LevelError: + return mirlogging.LevelError + case ipfslogging.LevelDPanic: + return mirlogging.LevelError + case ipfslogging.LevelPanic: + return mirlogging.LevelError + case ipfslogging.LevelFatal: + return mirlogging.LevelError + default: + return mirlogging.LevelError + } } func (l *managerLogger) IsConcurrent() bool { diff --git a/chain/consensus/mir/manager.go b/chain/consensus/mir/manager.go index f36da08e4..ea1cfd8c2 100644 --- a/chain/consensus/mir/manager.go +++ b/chain/consensus/mir/manager.go @@ -361,7 +361,7 @@ func (m *Manager) GetMessages(batch *Batch) (msgs []*types.SignedMessage, crossM switch msg := input.(type) { case *types.SignedMessage: - found := m.Pool.DeleteRequest(msg.Cid().String()) + found := m.Pool.DeleteRequest(msg.Cid()) if !found { log.Errorf("unable to find a request with %v hash", msg.Cid()) continue @@ -369,7 +369,7 @@ func (m *Manager) GetMessages(batch *Batch) (msgs []*types.SignedMessage, crossM msgs = append(msgs, msg) log.Infof("got message: to=%s, nonce= %d", msg.Message.To, msg.Message.Nonce) case *types.UnverifiedCrossMsg: - found := m.Pool.DeleteRequest(msg.Cid().String()) + found := m.Pool.DeleteRequest(msg.Cid()) if !found { log.Errorf("unable to find a request with %v hash", msg.Cid()) continue @@ -427,7 +427,7 @@ func (m *Manager) batchSignedMessages(msgs []*types.SignedMessage) ( Data: data, } - m.Pool.AddRequest(msg.Cid().String(), r) + m.Pool.AddRequest(msg.Cid(), r) requests = append(requests, r) } @@ -463,7 +463,7 @@ func (m *Manager) batchCrossMessages(crossMsgs []*types.UnverifiedCrossMsg) ( Type: TransportType, Data: data, } - m.Pool.AddRequest(msg.Cid().String(), r) + m.Pool.AddRequest(msg.Cid(), r) requests = append(requests, r) } return requests diff --git a/chain/consensus/mir/pool/fifo/fifo_pool.go b/chain/consensus/mir/pool/fifo/fifo_pool.go index 03d7d61be..8daf012b4 100644 --- a/chain/consensus/mir/pool/fifo/fifo_pool.go +++ b/chain/consensus/mir/pool/fifo/fifo_pool.go @@ -1,6 +1,8 @@ package fifo import ( + "github.com/ipfs/go-cid" + mirrequest "github.com/filecoin-project/mir/pkg/pb/requestpb" ) @@ -9,19 +11,19 @@ import ( // When we receive a message we find the clientID and remove it from orderingClients. // We don't need using sync primitives since the pool's methods are called only by one goroutine. type Pool struct { - clientByCID map[string]string // messageCID -> clientID - orderingClients map[string]bool // clientID -> bool + clientByCID map[cid.Cid]string // messageCID -> clientID + orderingClients map[string]bool // clientID -> bool } func New() *Pool { return &Pool{ - clientByCID: make(map[string]string), + clientByCID: make(map[cid.Cid]string), orderingClients: make(map[string]bool), } } // AddRequest adds the request if it satisfies to the FIFO policy. -func (p *Pool) AddRequest(cid string, r *mirrequest.Request) (exist bool) { +func (p *Pool) AddRequest(cid cid.Cid, r *mirrequest.Request) (exist bool) { _, exist = p.orderingClients[r.ClientId] if !exist { p.clientByCID[cid] = r.ClientId @@ -38,7 +40,7 @@ func (p *Pool) IsTargetRequest(clientID string) bool { } // DeleteRequest deletes the target request by the key h. -func (p *Pool) DeleteRequest(cid string) (ok bool) { +func (p *Pool) DeleteRequest(cid cid.Cid) (ok bool) { clientID, ok := p.clientByCID[cid] if ok { delete(p.orderingClients, clientID) diff --git a/chain/consensus/mir/pool/fifo/fifo_pool_test.go b/chain/consensus/mir/pool/fifo/fifo_pool_test.go index 9a991960e..11204f447 100644 --- a/chain/consensus/mir/pool/fifo/fifo_pool_test.go +++ b/chain/consensus/mir/pool/fifo/fifo_pool_test.go @@ -16,20 +16,20 @@ func TestMirFIFOPool(t *testing.T) { c1 := cid.NewCidV0(u.Hash([]byte("req1"))) c2 := cid.NewCidV0(u.Hash([]byte("req2"))) - inProgress := p.AddRequest(c1.String(), &mirrequest.Request{ + inProgress := p.AddRequest(c1, &mirrequest.Request{ ClientId: "client1", Data: []byte{}, }) require.Equal(t, false, inProgress) - inProgress = p.AddRequest(c1.String(), &mirrequest.Request{ + inProgress = p.AddRequest(c1, &mirrequest.Request{ ClientId: "client1", Data: []byte{}, }) require.Equal(t, true, inProgress) - inProgress = p.DeleteRequest(c1.String()) + inProgress = p.DeleteRequest(c1) require.Equal(t, true, inProgress) - inProgress = p.DeleteRequest(c2.String()) + inProgress = p.DeleteRequest(c2) require.Equal(t, false, inProgress) } diff --git a/chain/consensus/mir/state_manager.go b/chain/consensus/mir/state_manager.go index f5dc9d36a..771a34120 100644 --- a/chain/consensus/mir/state_manager.go +++ b/chain/consensus/mir/state_manager.go @@ -4,8 +4,6 @@ import ( "bytes" "fmt" - "github.com/multiformats/go-multiaddr" - "github.com/filecoin-project/lotus/chain/consensus/hierarchical" availabilityevents "github.com/filecoin-project/mir/pkg/availability/events" "github.com/filecoin-project/mir/pkg/events" @@ -257,13 +255,7 @@ func (sm *StateManager) applyRestoreState(snapshot *commonpb.StateSnapshot) (*ev for e, membership := range snapshot.Configuration.Memberships { sm.memberships[t.EpochNr(e)] = make(map[t.NodeID]t.NodeAddress) - for nID, nAddr := range membership.Membership { - var err error - sm.memberships[t.EpochNr(e)][t.NodeID(nID)], err = multiaddr.NewMultiaddr(nAddr) - if err != nil { - return nil, err - } - } + sm.memberships[t.EpochNr(e)] = t.Membership(membership) } newMembership := maputil.Copy(sm.memberships[t.EpochNr(snapshot.Configuration.EpochNr+ConfigOffset)])