libplanet icon indicating copy to clipboard operation
libplanet copied to clipboard

`ConsensusContext.HandleMessage()` creates context with earlier validator set

Open OnedgeLee opened this issue 1 year ago • 1 comments

If ConsensusContext receives a message with higher height than current height, it tries to create a new Context with height of received message via ConsensusContext.CreateContext(). https://github.com/planetarium/libplanet/blob/690a98c0664abf024c89dc52a04b14e9f6943eaa/Libplanet.Net/Consensus/ConsensusContext.cs#L250-L253

But ConsensusContext.CreateContext() creates Context with validator set of ConsensusContext.Height - 1, so validator set of created Context is different from actual one, if ConsensusMessage.Height != ConsensusContext.Height. https://github.com/planetarium/libplanet/blob/690a98c0664abf024c89dc52a04b14e9f6943eaa/Libplanet.Net/Consensus/ConsensusContext.cs#L442-L444

It does not make any critical problems if validator set is static, but when it varies, can be a matter.

Since Context cannot be generated without validator set, and validator set cannot be decided without actual block appending, Context should not be created through this path, IMO.

OnedgeLee avatar Apr 30 '24 01:04 OnedgeLee