-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Conversation
fc::datastream<char*> ds(bytes, sizeof(bytes)); | ||
fc::raw::pack(ds, header); | ||
EOS_ASSERT(!ds.remaining(), chain::plugin_exception, "state_history_log_header_serial_size mismatch"); | ||
log.write(bytes, sizeof(bytes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though it should be the same in this case, it is better use ds.tellp()
rather than sizeof(bytes)
here.
log.seekg(0, std::ios_base::end); | ||
uint64_t pos = log.tellg(); | ||
log.write((char*)&header, sizeof(header)); | ||
write_header(header); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could store the position right after writing the header but before writing the payload:
uint64_t payload_start_pos = log.tellg();
write_payload(log); | ||
uint64_t end = log.tellg(); | ||
EOS_ASSERT(end == pos + sizeof(header) + header.payload_size, chain::plugin_exception, | ||
EOS_ASSERT(end == pos + state_history_log_header_serial_size + header.payload_size, chain::plugin_exception, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then here the condition could be end == payload_start_pos + header.payload_size
.
if (suffix + sizeof(header) + header.payload_size + sizeof(suffix) != size) { | ||
read_header(header, false); | ||
if (!is_ship(header.magic) || !is_ship_supported_version(header.magic) || | ||
suffix + state_history_log_header_serial_size + header.payload_size + sizeof(suffix) != size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last part of condition could be log.tellg() + header.payload_size + sizeof(suffix) != size
.
uint64_t suffix; | ||
if (header.payload_size > size || pos + sizeof(header) + header.payload_size + sizeof(suffix) > size) | ||
if (!is_ship(header.magic) || !is_ship_supported_version(header.magic) || header.payload_size > size || | ||
pos + state_history_log_header_serial_size + header.payload_size + sizeof(suffix) > size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last part of condition could be log.tellg() + header.payload_size + sizeof(suffix) > size
.
break; | ||
log.seekg(pos + sizeof(header) + header.payload_size); | ||
} | ||
log.seekg(pos + state_history_log_header_serial_size + header.payload_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with log.seekg( log.tellg() + header.payload_size )
.
log.read((char*)&suffix, sizeof(suffix)); | ||
if (suffix != pos) | ||
break; | ||
pos = pos + sizeof(header) + header.payload_size + sizeof(suffix); | ||
pos = pos + state_history_log_header_serial_size + header.payload_size + sizeof(suffix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with pos = log.tellg()
.
EOS_ASSERT(header.version == 0 && sizeof(header) + header.payload_size + sizeof(uint64_t) <= size, | ||
read_header(header, false); | ||
EOS_ASSERT(is_ship(header.magic) && is_ship_supported_version(header.magic) && | ||
state_history_log_header_serial_size + header.payload_size + sizeof(uint64_t) <= size, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last part of condition could be log.tellg() + header.payload_size + sizeof(uint64_t) <= size
.
log.read((char*)&header, sizeof(header)); | ||
uint64_t suffix_pos = pos + sizeof(header) + header.payload_size; | ||
read_header(header, false); | ||
uint64_t suffix_pos = pos + state_history_log_header_serial_size + header.payload_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with uint64_t suffix_pos = log.tellg() + header.payload_size;
.
log.seekg(suffix_pos); | ||
log.read((char*)&suffix, sizeof(suffix)); | ||
// ilog("block ${b} at ${pos}-${end} suffix=${suffix} file_size=${fs}", | ||
// ("b", header.block_num)("pos", pos)("end", suffix_pos + sizeof(suffix))("suffix", suffix)("fs", size)); | ||
EOS_ASSERT(suffix == pos, chain::plugin_exception, "corrupt ${name}.log (8)", ("name", name)); | ||
|
||
state_history_summary summary{.pos = pos}; | ||
index.write((char*)&summary, sizeof(summary)); | ||
index.write((char*)&pos, sizeof(pos)); | ||
pos = suffix_pos + sizeof(suffix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also just be pos = log.tellg();
.
We will skip the above changes for now since it only goes partially towards removing the dependency on the |
Change Description
Replace ship's header to address these concerns in #5970:
These changes, plus changes in other PRs, make ship files incompatible with previous nodeos versions.
Consensus Changes
API Changes
Documentation Additions