Skip to content

Commit

Permalink
Merge pull request #135 from boscore/release/3.0.x
Browse files Browse the repository at this point in the history
v3.0.4 to master
  • Loading branch information
Thaipanda authored Nov 4, 2019
2 parents f117534 + 34c12f4 commit c8869e6
Show file tree
Hide file tree
Showing 15 changed files with 532 additions and 354 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ set( CXX_STANDARD_REQUIRED ON)

set(VERSION_MAJOR 3)
set(VERSION_MINOR 0)
set(VERSION_PATCH 3)
set(VERSION_PATCH 4)

if(VERSION_SUFFIX)
set(VERSION_FULL "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_SUFFIX}")
Expand Down
4 changes: 2 additions & 2 deletions Docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ cd bos/Docker
docker build . -t boscore/bos -s BOS
```

The above will build off the most recent commit to the master branch by default. If you would like to target a specific branch/tag, you may use a build argument. For example, if you wished to generate a docker image based off of the v3.0.3 tag, you could do the following:
The above will build off the most recent commit to the master branch by default. If you would like to target a specific branch/tag, you may use a build argument. For example, if you wished to generate a docker image based off of the v3.0.4 tag, you could do the following:

```bash
docker build -t boscore/bos:v3.0.3 --build-arg branch=v3.0.3 .
docker build -t boscore/bos:v3.0.4 --build-arg branch=v3.0.4 .

```

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# BOSCore - Born for DApps. Born for Usability.

## BOSCore Version: v3.0.3
### Basic EOSIO Version: v1.6.6 (support REX)
## BOSCore Version: v3.0.4
### Basic EOSIO Version: v1.6.6 (support REX, part 1.8.x)

# Background
The emergence of EOS has brought new imagination to the blockchain. In just a few months since the main network was launched, the version has undergone dozens of upgrades, not only the stability has been greatly improved, but also the new functions have been gradually realized. The node team is also actively involved in building the EOSIO ecosystem. What is even more exciting is that EOS has attracted more and more development teams. There are already hundreds of DApp running on the EOS main network. The transaction volume and circulation market value far exceed Ethereum, and the space for development is growing broader.
Expand Down
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# BOSCore - 更可用的链,为DApp而生。

## BOSCore Version: v3.0.3
### Basic EOSIO Version: v1.6.6 (support REX)
## BOSCore Version: v3.0.4
### Basic EOSIO Version: v1.6.6 (support REX, part 1.8.x)

# 背景
EOS的出现给区块链带来了新的想象力,主网启动短短几个月以来,版本经历了几十次升级,不仅稳定性得到了很大提高,并且新功能也逐步实现,各个节点团队也积极参与建设EOSIO生态。让人更加兴奋的是,EOS已经吸引了越来越多的开发团队,当前已经有数百个DApp在EOS主网上面运行,其交易量和流通市值远超以太坊,可发展的空间愈来愈广阔。
Expand Down
122 changes: 76 additions & 46 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#define LOG_READ (std::ios::in | std::ios::binary)
#define LOG_WRITE (std::ios::out | std::ios::binary | std::ios::app)
#define LOG_RW ( std::ios::in | std::ios::out | std::ios::binary )

namespace eosio { namespace chain {

Expand All @@ -32,42 +31,47 @@ namespace eosio { namespace chain {
std::fstream index_stream;
fc::path block_file;
fc::path index_file;
bool open_files = false;
bool block_write;
bool index_write;
bool genesis_written_to_block_log = false;
uint32_t version = 0;
uint32_t first_block_num = 0;

inline void check_open_files() {
if( !open_files ) {
reopen();
inline void check_block_read() {
if (block_write) {
block_stream.close();
block_stream.open(block_file.generic_string().c_str(), LOG_READ);
block_write = false;
}
}
void reopen();

void close() {
if( block_stream.is_open() )
inline void check_block_write() {
if (!block_write) {
block_stream.close();
if( index_stream.is_open() )
index_stream.close();
open_files = false;
block_stream.open(block_file.generic_string().c_str(), LOG_WRITE);
block_write = true;
}
}
};

void block_log_impl::reopen() {
close();

// open to create files if they don't exist
//ilog("Opening block log at ${path}", ("path", my->block_file.generic_string()));
block_stream.open(block_file.generic_string().c_str(), LOG_WRITE);
index_stream.open(index_file.generic_string().c_str(), LOG_WRITE);

close();

block_stream.open(block_file.generic_string().c_str(), LOG_RW);
index_stream.open(index_file.generic_string().c_str(), LOG_RW);
inline void check_index_read() {
try {
if (index_write) {
index_stream.close();
index_stream.open(index_file.generic_string().c_str(), LOG_READ);
index_write = false;
}
}
FC_LOG_AND_RETHROW()
}

open_files = true;
}
inline void check_index_write() {
if (!index_write) {
index_stream.close();
index_stream.open(index_file.generic_string().c_str(), LOG_WRITE);
index_write = true;
}
}
};
}

block_log::block_log(const fc::path& data_dir)
Expand All @@ -84,21 +88,26 @@ namespace eosio { namespace chain {
block_log::~block_log() {
if (my) {
flush();
my->close();
my.reset();
}
}

void block_log::open(const fc::path& data_dir) {
my->close();
if (my->block_stream.is_open())
my->block_stream.close();
if (my->index_stream.is_open())
my->index_stream.close();

if (!fc::is_directory(data_dir))
fc::create_directories(data_dir);

my->block_file = data_dir / "blocks.log";
my->index_file = data_dir / "blocks.index";

my->reopen();
//ilog("Opening block log at ${path}", ("path", my->block_file.generic_string()));
my->block_stream.open(my->block_file.generic_string().c_str(), LOG_WRITE);
my->index_stream.open(my->index_file.generic_string().c_str(), LOG_WRITE);
my->block_write = true;
my->index_write = true;

/* On startup of the block log, there are several states the log file and the index file can be
* in relation to each other.
Expand All @@ -123,6 +132,7 @@ namespace eosio { namespace chain {

if (log_size) {
ilog("Log is nonempty");
my->check_block_read();
my->block_stream.seekg( 0 );
my->version = 0;
my->block_stream.read( (char*)&my->version, sizeof(my->version) );
Expand All @@ -149,6 +159,9 @@ namespace eosio { namespace chain {
}

if (index_size) {
my->check_block_read();
my->check_index_read();

ilog("Index is nonempty");
uint64_t block_pos;
my->block_stream.seekg(-sizeof(uint64_t), std::ios::end);
Expand All @@ -171,20 +184,20 @@ namespace eosio { namespace chain {
}
} else if (index_size) {
ilog("Index is nonempty, remove and recreate it");
my->close();
my->index_stream.close();
fc::remove_all(my->index_file);
my->reopen();
my->index_stream.open(my->index_file.generic_string().c_str(), LOG_WRITE);
my->index_write = true;
}
}

uint64_t block_log::append(const signed_block_ptr& b) {
try {
EOS_ASSERT( my->genesis_written_to_block_log, block_log_append_fail, "Cannot append to block log until the genesis is first written" );

my->check_open_files();
my->check_block_write();
my->check_index_write();

my->block_stream.seekp(0, std::ios::end);
my->index_stream.seekp(0, std::ios::end);
uint64_t pos = my->block_stream.tellp();
EOS_ASSERT(my->index_stream.tellp() == sizeof(uint64_t) * (b->block_num() - my->first_block_num),
block_log_append_fail,
Expand All @@ -211,17 +224,22 @@ namespace eosio { namespace chain {
}

void block_log::reset( const genesis_state& gs, const signed_block_ptr& first_block, uint32_t first_block_num ) {
my->close();
if (my->block_stream.is_open())
my->block_stream.close();
if (my->index_stream.is_open())
my->index_stream.close();

fc::remove_all(my->block_file);
fc::remove_all(my->index_file);

my->reopen();
my->block_stream.open(my->block_file.generic_string().c_str(), LOG_WRITE);
my->index_stream.open(my->index_file.generic_string().c_str(), LOG_WRITE);
my->block_write = true;
my->index_write = true;

auto data = fc::raw::pack(gs);
my->version = 0; // version of 0 is invalid; it indicates that the genesis was not properly written to the block log
my->first_block_num = first_block_num;
my->block_stream.seekp(0, std::ios::end);
my->block_stream.write((char*)&my->version, sizeof(my->version));
my->block_stream.write((char*)&my->first_block_num, sizeof(my->first_block_num));
my->block_stream.write(data.data(), data.size());
Expand All @@ -233,20 +251,29 @@ namespace eosio { namespace chain {

if (first_block) {
append(first_block);
} else {
my->head.reset();
my->head_id = {};
}

auto pos = my->block_stream.tellp();

my->block_stream.close();
my->block_stream.open(my->block_file.generic_string().c_str(), std::ios::in | std::ios::out | std::ios::binary ); // Bypass append-only writing just once

static_assert( block_log::max_supported_version > 0, "a version number of zero is not supported" );
my->version = block_log::max_supported_version;
my->block_stream.seekp( 0 );
my->block_stream.write( (char*)&my->version, sizeof(my->version) );
my->block_stream.seekp( pos );
flush();

my->block_write = false;
my->check_block_write(); // Reset to append-only writing.
}

std::pair<signed_block_ptr, uint64_t> block_log::read_block(uint64_t pos)const {
my->check_open_files();
my->check_block_read();

my->block_stream.seekg(pos);
std::pair<signed_block_ptr,uint64_t> result;
Expand All @@ -270,7 +297,7 @@ namespace eosio { namespace chain {
}

uint64_t block_log::get_block_pos(uint32_t block_num) const {
my->check_open_files();
my->check_index_read();
if (!(my->head && block_num <= block_header::num_from_id(my->head_id) && block_num >= my->first_block_num))
return npos;
my->index_stream.seekg(sizeof(uint64_t) * (block_num - my->first_block_num));
Expand All @@ -280,7 +307,7 @@ namespace eosio { namespace chain {
}

signed_block_ptr block_log::read_head()const {
my->check_open_files();
my->check_block_read();

uint64_t pos;

Expand Down Expand Up @@ -308,13 +335,13 @@ namespace eosio { namespace chain {

void block_log::construct_index() {
ilog("Reconstructing Block Log Index...");
my->close();

my->index_stream.close();
fc::remove_all(my->index_file);

my->reopen();
my->index_stream.open(my->index_file.generic_string().c_str(), LOG_WRITE);
my->index_write = true;

uint64_t end_pos;
my->check_block_read();

my->block_stream.seekg(-sizeof( uint64_t), std::ios::end);
my->block_stream.read((char*)&end_pos, sizeof(end_pos));
Expand Down Expand Up @@ -343,10 +370,11 @@ namespace eosio { namespace chain {
my->block_stream.read((char*) &totem, sizeof(totem));
}

my->index_stream.seekp(0, std::ios::end);
while( pos < end_pos ) {
fc::raw::unpack(my->block_stream, tmp);
my->block_stream.read((char*)&pos, sizeof(pos));
if(tmp.block_num() % 1000 == 0)
ilog( "Block log index reconstructed for block ${n}", ("n", tmp.block_num()));
my->index_stream.write((char*)&pos, sizeof(pos));
}
} // construct_index
Expand Down Expand Up @@ -468,6 +496,8 @@ namespace eosio { namespace chain {
new_block_stream.write( data.data(), data.size() );
new_block_stream.write( reinterpret_cast<char*>(&pos), sizeof(pos) );
block_num = tmp.block_num();
if(block_num % 1000 == 0)
ilog( "Recovered block ${num}", ("num", block_num) );
pos = new_block_stream.tellp();
if( block_num == truncate_at_block )
break;
Expand Down
13 changes: 4 additions & 9 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,14 @@ struct controller_impl {
auto start = fc::time_point::now();
while( auto next = blog.read_block_by_num( head->block_num + 1 ) ) {
replay_push_block( next, controller::block_status::irreversible );
if( next->block_num() % 100 == 0 ) {
std::cerr << std::setw(10) << next->block_num() << " of " << blog_head->block_num() <<"\r";
if( next->block_num() % 500 == 0 ) {
ilog( "${n} of ${head}", ("n", next->block_num())("head", blog_head->block_num()) );
if( shutdown() ) break;
}
}
std::cerr<< "\n";
ilog( "${n} blocks replayed", ("n", head->block_num - start_block_num) );

// if the irreverible log is played without undo sessions enabled, we need to sync the
// if the irreversible log is played without undo sessions enabled, we need to sync the
// revision ordinal to the appropriate expected value here.
if( self.skip_db_sessions( controller::block_status::irreversible ) )
db.set_revision(head->block_num);
Expand Down Expand Up @@ -389,7 +388,7 @@ struct controller_impl {
report_integrity_hash = true;
}
}

if( shutdown() ) return;

const auto& ubi = reversible_blocks.get_index<reversible_block_index,by_num>();
Expand Down Expand Up @@ -921,17 +920,14 @@ struct controller_impl {
void commit_block( bool add_to_fork_db ) {
auto reset_pending_on_exit = fc::make_scoped_exit([this]{
pending.reset();

});

try {

if (add_to_fork_db) {
pending->_pending_block_state->validated = true;

auto new_bsp = fork_db.add(pending->_pending_block_state, true, pbft_enabled);
emit(self.accepted_block_header, pending->_pending_block_state);

head = fork_db.head();
EOS_ASSERT(new_bsp == head, fork_database_exception, "committed block did not become the new head in fork database");
}
Expand Down Expand Up @@ -1381,7 +1377,6 @@ struct controller_impl {

pending->_pending_block_state->set_confirmed(confirm_block_count, pbft_enabled);


auto was_pending_promoted = pending->_pending_block_state->maybe_promote_pending(pbft_enabled);

//modify state in speculative block only if we are speculative reads mode (other wise we need clean state for head or irreversible reads)
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/eosio/chain/wasm_eosio_injection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,8 @@ namespace eosio { namespace chain { namespace wasm_injections {


struct post_op_injectors : wasm_ops::op_types<pass_injector> {
using loop_t = wasm_ops::loop <checktime_injection>;
using call_t = wasm_ops::call <fix_call_index>;
using loop_t = wasm_ops::loop <checktime_injection>;
using call_t = wasm_ops::call <fix_call_index>;
using grow_memory_t = wasm_ops::grow_memory <checktime_injection>;
};

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static bytes zlib_decompress(const bytes& data) {
bytes out;
bio::filtering_ostream decomp;
decomp.push(bio::zlib_decompressor());
decomp.push(read_limiter<1*1024*1024>()); // limit to 10 megs decompressed for zip bomb protections
decomp.push(read_limiter<1*1024*1024>()); // limit to 1 meg decompressed for zip bomb protections
decomp.push(bio::back_inserter(out));
bio::write(decomp, data.data(), data.size());
bio::close(decomp);
Expand Down
Loading

0 comments on commit c8869e6

Please sign in to comment.