Skip to content

Commit ac6ea47

Browse files
committed
feat: enforce nVersion bit for pubKeyOperator and netInfo bits in new format
1 parent f7963d4 commit ac6ea47

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/evo/dmnstate.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ class CDeterministicMNStateDiff
231231
}
232232
}
233233
});
234-
if (fields & Field_pubKeyOperator) {
235-
// pubKeyOperator needs nVersion
234+
if ((fields & Field_pubKeyOperator) || (fields & Field_netInfo)) {
235+
// pubKeyOperator and netInfo need nVersion
236236
state.nVersion = b.nVersion;
237237
fields |= Field_nVersion;
238238
}
@@ -246,33 +246,28 @@ class CDeterministicMNStateDiff
246246
{
247247
READWRITE(VARINT(obj.fields));
248248

249-
// NOTE: reading pubKeyOperator requires nVersion
250-
bool read_pubkey{false};
249+
if ((obj.fields & Field_pubKeyOperator) || (obj.fields & Field_netInfo)) {
250+
// pubKeyOperator and netInfo need nVersion
251+
assert(obj.fields & Field_nVersion);
252+
}
253+
251254
boost::hana::for_each(members, [&](auto&& member) {
252255
using BaseType = std::decay_t<decltype(member)>;
253256
if constexpr (BaseType::mask == Field_pubKeyOperator) {
254257
if (obj.fields & member.mask) {
255-
SER_READ(obj, read_pubkey = true);
256258
READWRITE(CBLSLazyPublicKeyVersionWrapper(const_cast<CBLSLazyPublicKey&>(obj.state.pubKeyOperator), obj.state.nVersion == ProTxVersion::LegacyBLS));
257259
}
258260
} else if constexpr (BaseType::mask == Field_netInfo) {
259261
if (obj.fields & member.mask) {
260-
// As nVersion is stored after netInfo, we use a magic word to determine the underlying implementation
261-
// TODO: Implement this
262262
READWRITE(NetInfoSerWrapper(const_cast<std::shared_ptr<NetInfoInterface>&>(obj.state.netInfo),
263-
/*is_extended=*/false));
263+
obj.state.nVersion == ProTxVersion::ExtAddr));
264264
}
265265
} else {
266266
if (obj.fields & member.mask) {
267267
READWRITE(member.get(obj.state));
268268
}
269269
}
270270
});
271-
272-
if (read_pubkey) {
273-
SER_READ(obj, obj.fields |= Field_nVersion);
274-
SER_READ(obj, obj.state.pubKeyOperator.SetLegacy(obj.state.nVersion == ProTxVersion::LegacyBLS));
275-
}
276271
}
277272

278273
void ApplyToState(CDeterministicMNState& target) const
@@ -352,7 +347,14 @@ class CDeterministicMNStateDiffLegacy
352347
CDeterministicMNStateDiffLegacy() = default;
353348

354349
template <typename Stream>
355-
CDeterministicMNStateDiffLegacy(deserialize_type, Stream& s) { s >> *this; }
350+
CDeterministicMNStateDiffLegacy(deserialize_type, Stream& s)
351+
{
352+
s >> *this;
353+
if ((fields & LegacyField_pubKeyOperator) || (fields & LegacyField_netInfo)) {
354+
// pubKeyOperator and netInfo need nVersion
355+
fields |= LegacyField_nVersion;
356+
}
357+
}
356358

357359
// Deserialize using legacy format
358360
SERIALIZE_METHODS(CDeterministicMNStateDiffLegacy, obj)

0 commit comments

Comments
 (0)