eos icon indicating copy to clipboard operation
eos copied to clipboard

The snapshot's magic_number is different when writing and reading files

Open XHQ18 opened this issue 8 years ago • 0 comments

Where magic_number writes to the snapshot file, I write the magic_number that I just wrote to the snapshot file to another file. Print the magic_number that is read from the snapshot file when parsing the magic_number value. These two values are different. Why?

//Write to snapshot file
ostream_snapshot_writer::ostream_snapshot_writer(std::ostream& snapshot)
:snapshot(snapshot)
,header_pos(snapshot.tellp())
,section_pos(-1)
,row_count(0)
{
   // write magic number
   auto totem = magic_number;
   snapshot.write((char*)&totem, sizeof(totem));
   //xhq
   auto temp = std::ofstream("/Users/xiehanqing/eosNew/eos/magicnumber.txt", (std::ios::out));
   temp << totem;
   temp.flush();
   temp.close();
   //end

   // write version
   auto version = current_snapshot_version;
   snapshot.write((char*)&version, sizeof(version));
}
//Parsing snapshot files
      auto expected_totem = ostream_snapshot_writer::magic_number;
      decltype(expected_totem) actual_totem;
      snapshot.read((char*)&actual_totem, sizeof(actual_totem));

      ilog( "${n} magic_number", ("n",actual_totem) );
//result
//The magic_number value written to the snapshot file
810616144
//Printed value
info  2018-11-06T03:39:43.138 thread-0  chain_plugin.cpp:333          plugin_initialize    ] initializing chain plugin
info  2018-11-06T03:39:43.138 thread-0  snapshot.cpp:220              validate             ] 32766 magic_number

XHQ18 avatar Nov 06 '18 04:11 XHQ18