Added stage slice config to control stage time allocation. (#310)

This commit is contained in:
Ravin Perera
2021-05-19 16:59:01 +05:30
committed by GitHub
parent 94b29b9e05
commit 45492f7c7f
15 changed files with 148 additions and 110 deletions

View File

@@ -27,7 +27,7 @@ table P2PMsg {
table PeerChallengeMsg {
contract_id:string;
roundtime:uint32;
time_config:uint32; // Contains unified value derived from (roundtime*100 + stage_slice)
is_full_history:bool;
challenge:[ubyte];
}
@@ -58,7 +58,7 @@ table ProposalMsg {
sig:[ubyte]; // Signature of the field data.
stage:uint8;
time:uint64;
roundtime:uint32;
time_config:uint32; // Contains unified value derived from (roundtime*100 + stage_slice)
nonce: [ubyte];
users:[ByteArray];
input_hashes:[ByteArray];

View File

@@ -70,7 +70,7 @@ namespace msg::fbuf::p2pmsg
flatbuf_hasher hasher;
hasher.add(msg.stage());
hasher.add(msg.time());
hasher.add(msg.roundtime());
hasher.add(msg.time_config());
hasher.add(msg.nonce());
hasher.add(msg.users());
hasher.add(msg.input_hashes());
@@ -110,7 +110,7 @@ namespace msg::fbuf::p2pmsg
const auto &msg = *mi.p2p_msg->content_as_PeerChallengeMsg();
return {
std::string(flatbuf_str_to_sv(msg.contract_id())),
msg.roundtime(),
msg.time_config(),
msg.is_full_history(),
std::string(flatbuf_bytes_to_sv(msg.challenge()))};
}
@@ -133,7 +133,7 @@ namespace msg::fbuf::p2pmsg
p.sent_timestamp = mi.originated_on;
p.recv_timestamp = util::get_epoch_milliseconds();
p.time = msg.time();
p.roundtime = msg.roundtime();
p.time_config = msg.time_config();
p.nonce = flatbuf_bytes_to_sv(msg.nonce());
p.stage = msg.stage();
p.state_hash = flatbuf_bytes_to_sv(msg.state_hash());
@@ -319,7 +319,7 @@ namespace msg::fbuf::p2pmsg
flatbuf_hasher hasher;
hasher.add(p.stage);
hasher.add(p.time);
hasher.add(p.roundtime);
hasher.add(p.time_config);
hasher.add(p.nonce);
hasher.add(p.users);
hasher.add(p.input_ordered_hashes);
@@ -361,7 +361,7 @@ namespace msg::fbuf::p2pmsg
const auto msg = CreatePeerChallengeMsg(
builder,
sv_to_flatbuf_str(builder, conf::cfg.contract.id),
conf::cfg.contract.roundtime,
CURRENT_TIME_CONFIG,
conf::cfg.node.history == conf::HISTORY::FULL,
sv_to_flatbuf_bytes(builder, challenge));
create_p2p_msg(builder, P2PMsgContent_PeerChallengeMsg, msg.Union());
@@ -396,7 +396,7 @@ namespace msg::fbuf::p2pmsg
sv_to_flatbuf_bytes(builder, generate_proposal_signature(p)),
p.stage,
p.time,
p.roundtime,
p.time_config,
sv_to_flatbuf_bytes(builder, p.nonce),
stringlist_to_flatbuf_bytearrayvector(builder, p.users),
stringlist_to_flatbuf_bytearrayvector(builder, p.input_ordered_hashes),

View File

@@ -543,7 +543,7 @@ struct PeerChallengeMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef PeerChallengeMsgBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_CONTRACT_ID = 4,
VT_ROUNDTIME = 6,
VT_TIME_CONFIG = 6,
VT_IS_FULL_HISTORY = 8,
VT_CHALLENGE = 10
};
@@ -553,11 +553,11 @@ struct PeerChallengeMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
flatbuffers::String *mutable_contract_id() {
return GetPointer<flatbuffers::String *>(VT_CONTRACT_ID);
}
uint32_t roundtime() const {
return GetField<uint32_t>(VT_ROUNDTIME, 0);
uint32_t time_config() const {
return GetField<uint32_t>(VT_TIME_CONFIG, 0);
}
bool mutate_roundtime(uint32_t _roundtime) {
return SetField<uint32_t>(VT_ROUNDTIME, _roundtime, 0);
bool mutate_time_config(uint32_t _time_config) {
return SetField<uint32_t>(VT_TIME_CONFIG, _time_config, 0);
}
bool is_full_history() const {
return GetField<uint8_t>(VT_IS_FULL_HISTORY, 0) != 0;
@@ -575,7 +575,7 @@ struct PeerChallengeMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
return VerifyTableStart(verifier) &&
VerifyOffset(verifier, VT_CONTRACT_ID) &&
verifier.VerifyString(contract_id()) &&
VerifyField<uint32_t>(verifier, VT_ROUNDTIME) &&
VerifyField<uint32_t>(verifier, VT_TIME_CONFIG) &&
VerifyField<uint8_t>(verifier, VT_IS_FULL_HISTORY) &&
VerifyOffset(verifier, VT_CHALLENGE) &&
verifier.VerifyVector(challenge()) &&
@@ -590,8 +590,8 @@ struct PeerChallengeMsgBuilder {
void add_contract_id(flatbuffers::Offset<flatbuffers::String> contract_id) {
fbb_.AddOffset(PeerChallengeMsg::VT_CONTRACT_ID, contract_id);
}
void add_roundtime(uint32_t roundtime) {
fbb_.AddElement<uint32_t>(PeerChallengeMsg::VT_ROUNDTIME, roundtime, 0);
void add_time_config(uint32_t time_config) {
fbb_.AddElement<uint32_t>(PeerChallengeMsg::VT_TIME_CONFIG, time_config, 0);
}
void add_is_full_history(bool is_full_history) {
fbb_.AddElement<uint8_t>(PeerChallengeMsg::VT_IS_FULL_HISTORY, static_cast<uint8_t>(is_full_history), 0);
@@ -614,12 +614,12 @@ struct PeerChallengeMsgBuilder {
inline flatbuffers::Offset<PeerChallengeMsg> CreatePeerChallengeMsg(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> contract_id = 0,
uint32_t roundtime = 0,
uint32_t time_config = 0,
bool is_full_history = false,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> challenge = 0) {
PeerChallengeMsgBuilder builder_(_fbb);
builder_.add_challenge(challenge);
builder_.add_roundtime(roundtime);
builder_.add_time_config(time_config);
builder_.add_contract_id(contract_id);
builder_.add_is_full_history(is_full_history);
return builder_.Finish();
@@ -628,7 +628,7 @@ inline flatbuffers::Offset<PeerChallengeMsg> CreatePeerChallengeMsg(
inline flatbuffers::Offset<PeerChallengeMsg> CreatePeerChallengeMsgDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const char *contract_id = nullptr,
uint32_t roundtime = 0,
uint32_t time_config = 0,
bool is_full_history = false,
const std::vector<uint8_t> *challenge = nullptr) {
auto contract_id__ = contract_id ? _fbb.CreateString(contract_id) : 0;
@@ -636,7 +636,7 @@ inline flatbuffers::Offset<PeerChallengeMsg> CreatePeerChallengeMsgDirect(
return msg::fbuf::p2pmsg::CreatePeerChallengeMsg(
_fbb,
contract_id__,
roundtime,
time_config,
is_full_history,
challenge__);
}
@@ -953,7 +953,7 @@ struct ProposalMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_SIG = 6,
VT_STAGE = 8,
VT_TIME = 10,
VT_ROUNDTIME = 12,
VT_TIME_CONFIG = 12,
VT_NONCE = 14,
VT_USERS = 16,
VT_INPUT_HASHES = 18,
@@ -988,11 +988,11 @@ struct ProposalMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
bool mutate_time(uint64_t _time) {
return SetField<uint64_t>(VT_TIME, _time, 0);
}
uint32_t roundtime() const {
return GetField<uint32_t>(VT_ROUNDTIME, 0);
uint32_t time_config() const {
return GetField<uint32_t>(VT_TIME_CONFIG, 0);
}
bool mutate_roundtime(uint32_t _roundtime) {
return SetField<uint32_t>(VT_ROUNDTIME, _roundtime, 0);
bool mutate_time_config(uint32_t _time_config) {
return SetField<uint32_t>(VT_TIME_CONFIG, _time_config, 0);
}
const flatbuffers::Vector<uint8_t> *nonce() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_NONCE);
@@ -1056,7 +1056,7 @@ struct ProposalMsg FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
verifier.VerifyVector(sig()) &&
VerifyField<uint8_t>(verifier, VT_STAGE) &&
VerifyField<uint64_t>(verifier, VT_TIME) &&
VerifyField<uint32_t>(verifier, VT_ROUNDTIME) &&
VerifyField<uint32_t>(verifier, VT_TIME_CONFIG) &&
VerifyOffset(verifier, VT_NONCE) &&
verifier.VerifyVector(nonce()) &&
VerifyOffset(verifier, VT_USERS) &&
@@ -1097,8 +1097,8 @@ struct ProposalMsgBuilder {
void add_time(uint64_t time) {
fbb_.AddElement<uint64_t>(ProposalMsg::VT_TIME, time, 0);
}
void add_roundtime(uint32_t roundtime) {
fbb_.AddElement<uint32_t>(ProposalMsg::VT_ROUNDTIME, roundtime, 0);
void add_time_config(uint32_t time_config) {
fbb_.AddElement<uint32_t>(ProposalMsg::VT_TIME_CONFIG, time_config, 0);
}
void add_nonce(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> nonce) {
fbb_.AddOffset(ProposalMsg::VT_NONCE, nonce);
@@ -1145,7 +1145,7 @@ inline flatbuffers::Offset<ProposalMsg> CreateProposalMsg(
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> sig = 0,
uint8_t stage = 0,
uint64_t time = 0,
uint32_t roundtime = 0,
uint32_t time_config = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> nonce = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::ByteArray>>> users = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::ByteArray>>> input_hashes = 0,
@@ -1166,7 +1166,7 @@ inline flatbuffers::Offset<ProposalMsg> CreateProposalMsg(
builder_.add_input_hashes(input_hashes);
builder_.add_users(users);
builder_.add_nonce(nonce);
builder_.add_roundtime(roundtime);
builder_.add_time_config(time_config);
builder_.add_sig(sig);
builder_.add_pubkey(pubkey);
builder_.add_stage(stage);
@@ -1179,7 +1179,7 @@ inline flatbuffers::Offset<ProposalMsg> CreateProposalMsgDirect(
const std::vector<uint8_t> *sig = nullptr,
uint8_t stage = 0,
uint64_t time = 0,
uint32_t roundtime = 0,
uint32_t time_config = 0,
const std::vector<uint8_t> *nonce = nullptr,
const std::vector<flatbuffers::Offset<msg::fbuf::p2pmsg::ByteArray>> *users = nullptr,
const std::vector<flatbuffers::Offset<msg::fbuf::p2pmsg::ByteArray>> *input_hashes = nullptr,
@@ -1204,7 +1204,7 @@ inline flatbuffers::Offset<ProposalMsg> CreateProposalMsgDirect(
sig__,
stage,
time,
roundtime,
time_config,
nonce__,
users__,
input_hashes__,