Closed Lavode closed 1 year ago
Thank's for looking into this!
The idea is that when someone uses the RegisterModule
function, the constructor function will decide which interface will be visible to the module system, through the return value's type. You can see this when using --list-modules
once it is fixed :)
❯ ./hotstuff --list-modules
(github.com/relab/hotstuff/consensus).Rules :
chainedhotstuff
fasthotstuff
simplehotstuff
(github.com/relab/hotstuff/modules).Handel :
handel
(github.com/relab/hotstuff/modules).LeaderRotation :
round-robin
carousel
fixed
reputation
(github.com/relab/hotstuff/modules).CryptoBase :
bls12
ecdsa
(github.com/relab/hotstuff/consensus/byzantine).Byzantine :
silence
fork
The
--list-modules
CLI flag produces a segfault:Following the stack trace shows it must be due to the
t
variable, a key of thebyInterface
map, being<nil>
: https://github.com/relab/hotstuff/blob/master/modules/registry.go#L89The queried datastructure (
byInterface
) is only filled within here, where the offending map key is calledmoduleType
: https://github.com/relab/hotstuff/blob/master/modules/registry.go#L31-L34moduleType
is set in the same function asmoduleType := reflect.TypeOf(t)
. Here,var t T
is (the zero value of) a variable of typeT
.T
is seemingly the (generic) return type of the constructor of the module which is being registered.Which brings us to the likely cause. The return type of at least some of the registered modules' constructors is an interface, e.g here: https://github.com/relab/hotstuff/blob/master/consensus/byzantine/byzantine.go#L11
Thus
var t T
has the zero value of an interface, which is<nil>
.moduleType := reflect.TypeOf(t)
returnsnil
ast
is anil
interface. This ends up in thebyInterface
map. And eventually it blows up when one tries to access it as something of typereflect.Type
.I don't understand why you seemingly keep modules grouped by their constructor's return value in the
byInterface
data structure, and why you want to print them that way in the--list-modules
call, so am hesitant to recommend a fix.