Skip to content

Commit

Permalink
add feature
Browse files Browse the repository at this point in the history
  • Loading branch information
justfortest2 committed May 6, 2020
1 parent 9ed0bd4 commit 3aba2cb
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 38 deletions.
11 changes: 8 additions & 3 deletions ibc.chain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ Actions called by administrator
must be one of `pipeline` (represent DPOS pipeline bft consensus, such as the current EOSIO mainnet consensus)
and `batch` (represent DPOS batch pbft consensus, such as the new BOS 3 seconds LIB consensus).
- require auth of _self


#### setadmin( admin )
- **admin**, admin account.
- require auth of _self

#### forceinit( )
- three table ( _chaindb, _prodsches, _sections ) will be clear.
- this action is needed when repairing the ibc system manually,
please refer to [TROUBLESHOOTING](../docs/Troubles_Shooting.md) for detailed IBC system recovery process.
- require auth of _self
- require auth of _self or admin

Actions called by ibc_plugin
----------------------------
Expand Down Expand Up @@ -66,7 +70,8 @@ ibc.token : `cash`,`rollback`,`rmunablerb`
#### void relay( string action, name relay )
- **action**, the string value must be **`add`** to add a relay to the relay set or **`remove`** to remove a relay, you can add multiple relays.
- **relay**, the relay account.

- require auth of _self or admin

#### void reqrelayauth( )
This action is used to facilitate the administrator to check the value of `check_relay_auth`, because this parameter is hard coded in the code and cannot be viewed through the contract table.

Expand Down
13 changes: 13 additions & 0 deletions ibc.chain/include/ibc.chain/ibc.chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace eosio {

const static bool check_relay_auth = true;

struct [[eosio::table("admin"), eosio::contract("ibc.chain")]] admin_struct {
name admin;
EOSLIB_SERIALIZE( admin_struct, (admin))
};
typedef eosio::singleton< "admin"_n, admin_struct > admin_singleton;

struct [[eosio::table("global"), eosio::contract("ibc.chain")]] global_state {
name chain_name; // the original chain name, ibc_plugin uses this name to interact with the ibc.token contract
chain_id_type chain_id;
Expand Down Expand Up @@ -100,6 +106,8 @@ namespace eosio {
global_state _gstate;
global_mutable_singleton _global_mutable;
global_mutable _gmutable;
admin_singleton _admin_sg;
admin_struct _admin_st;
chaindb _chaindb;
prodsches _prodsches;
sections _sections;
Expand All @@ -114,6 +122,9 @@ namespace eosio {
chain_id_type chain_id,
name consensus_algo );

[[eosio::action]]
void setadmin( name admin );

[[eosio::action]]
void chaininit( const std::vector<char>& header,
const producer_schedule& active_schedule,
Expand Down Expand Up @@ -211,6 +222,8 @@ namespace eosio {
capi_public_key get_public_key_form_signature( digest_type digest, signature_type sig ) const;

bool only_one_eosio_bp();

void check_admin_auth();
};

} /// namespace eosio
21 changes: 18 additions & 3 deletions ibc.chain/src/ibc.chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace eosio {

chain::chain( name s, name code, datastream<const char*> ds ) :contract(s,code,ds),
_global_state(_self, _self.value),
_admin_sg(_self, _self.value),
_global_mutable(_self, _self.value),
_chaindb(_self, _self.value),
_prodsches(_self, _self.value),
Expand All @@ -19,11 +20,13 @@ namespace eosio {
{
_gstate = _global_state.exists() ? _global_state.get() : global_state{};
_gmutable = _global_mutable.exists() ? _global_mutable.get() : global_mutable{};
_admin_st = _admin_sg.exists() ? _admin_sg.get() : admin_struct{};
}

chain::~chain() {
_global_state.set( _gstate, _self );
_global_mutable.set( _gmutable, _self );
_admin_sg.set( _admin_st , _self );
}

void chain::setglobal( name chain_name,
Expand All @@ -38,6 +41,11 @@ namespace eosio {
_gstate.consensus_algo = consensus_algo;
}

void chain::setadmin( name admin ){
require_auth( _self );
_admin_st.admin = admin;
}

// init for both pipeline and batch light client
void chain::chaininit( const std::vector<char>& header_data,
const producer_schedule& active_schedule,
Expand Down Expand Up @@ -840,7 +848,7 @@ namespace eosio {
// ------ force init ------ //

void chain::forceinit(){
require_auth(_self);
check_admin_auth();
while ( _prodsches.begin() != _prodsches.end() ){ _prodsches.erase(_prodsches.begin()); }
while ( _sections.begin() != _sections.end() ){ _sections.erase(_sections.begin()); }
_gmutable = global_mutable{};
Expand Down Expand Up @@ -869,7 +877,7 @@ namespace eosio {
}

void chain::relay( string action, name relay ) {
require_auth( _self );
check_admin_auth();
auto existing = _relays.find( relay.value );

if ( action == "add" ) {
Expand All @@ -895,6 +903,13 @@ namespace eosio {
}
}

void chain::check_admin_auth(){
if ( ! has_auth(_self) ){
eosio_assert( _admin_st.admin != name() && is_account( _admin_st.admin ),"admin account not exist");
require_auth( _admin_st.admin );
}
}

} /// namespace eosio

EOSIO_DISPATCH( eosio::chain, (setglobal)(chaininit)(pushsection)(rmfirstsctn)(pushblkcmits)(forceinit)(relay)(reqrelayauth) )
EOSIO_DISPATCH( eosio::chain, (setglobal)(chaininit)(pushsection)(rmfirstsctn)(pushblkcmits)(forceinit)(relay)(reqrelayauth)(setadmin) )
32 changes: 18 additions & 14 deletions ibc.token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Actions called by administrators
Only when _global_state.active is true can the original IBC transaction be successfully executed.
- require auth of _self

#### setadmin( admin )
- **admin**, admin account.
- require auth of _self

#### regpeerchain
```
void regpeerchain( name peerchain_name,
Expand Down Expand Up @@ -69,7 +73,7 @@ Actions called by administrators
- **cache_cashtrxs_table_records** maximum cashtrxs table records, the recommended value is 1000.
- **active** set the initial active state (_peerchains.active).
Only when _peerchains.active is true can the original IBC transaction to this peer chain be successfully executed.
- require auth of _self
- require auth of _self or admin

Examples:
The following examples assume that IBC systems are deployed between the EOS and BOS mainnet,
Expand All @@ -90,7 +94,7 @@ void setchainbool( name peerchain_name, string which, bool value );
- **which**, must be 'active'
- **value**, bool value, set the active state (_peerchains.active).
Only when _peerchains.active is true can the original IBC transaction to this peer chain be successfully executed.
- require auth of _self
- require auth of _self or admin

#### regacpttoken
```
Expand Down Expand Up @@ -125,7 +129,7 @@ This action is used to register blockchain native token, which is originally iss
- **failed_fee** use this value to calculate fee for the filed original transaction.
- **active** set the initial active state of this token,
when active is false, IBC transfers are not allowed, but **cash**s trigger by peerchain action **withdraw** can still execute.
- require auth of _self
- require auth of _self or admin

Note: from IBC version 4, the pegged token symbol must same with the original token symbol.

Expand Down Expand Up @@ -170,7 +174,7 @@ Modify only one member of type `int` in currency_accept struct.
- **symcode** the token symbol code
- **which** must be "max_tfs_per_minute".
- **value** the value to be set.
- require auth of _self
- require auth of _self or admin

#### setacptbool
```
Expand All @@ -196,7 +200,7 @@ Modify fee related members in currency_accept struct.
- **fee_mode** must be "fixed" or "ratio".
- **fee_fixed** fixed fee quota, used when fee_mode == fixed
- **fee_ratio** charge ratio, used when fee_mode == ratio
- require auth of _self
- require auth of _self or admin

#### regpegtoken
```
Expand Down Expand Up @@ -224,7 +228,7 @@ This action is used to register pegged token, which is originally issued on othe
- **failed_fee** use this value to calculate fee for the filed withdraw transaction.
- **active** set the initial active state of this pegged token,
when active is false, IBC withdraws are not allowed, but **cash**s trigger by peerchain action **transfer** can still execute.
- require auth of _self
- require auth of _self or admin

```
contract_token=ibc2token555
Expand Down Expand Up @@ -275,7 +279,7 @@ this action equals call regpegtoken(...) firstly and then call regacpttoken(...)
- **failed_fee** use this value to calculate fee for the filed transfer transaction.
- **active** set the initial active state of this pegged token,
when active is false, IBC transfers are not allowed, but **cash**s trigger by peerchain action **transfer** can still execute.
- require auth of _self
- require auth of _self or admin

```
contract_token=ibc2token555
Expand Down Expand Up @@ -322,7 +326,7 @@ Modify only one member of type `bool` in currency_stats struct.
Modify fee related members in currency_stats struct.
- **symcode** the symcode of registered pegged token.
- **fee** fixed fee quota
- require auth of _self
- require auth of _self or admin

#### unregtoken
```
Expand All @@ -332,7 +336,7 @@ Modify fee related members in currency_stats struct.
- **table** table name, table name must be one of `all` ,`accepts` and `stats`,
when it's `all`, all records in table `accepts` or `stats` will be deleted.
- **sym_code** token symbol code, e.g. `BOS`,`EOS`.
- require auth of _self
- require auth of _self or admin

#### fcrollback
```
Expand All @@ -342,7 +346,7 @@ Modify fee related members in currency_stats struct.
used to force rollback (refund) specified original transaction records in table `origtrxs`.
- **peerchain_name** peer chain name.
- **trxs** original transactions that need to be rolled back.
- require auth of _self
- require auth of _self or admin

#### fcrmorigtrx
```
Expand All @@ -352,23 +356,23 @@ Modify fee related members in currency_stats struct.
used to force remove specified original transaction records in table `origtrxs`.
- **peerchain_name** peer chain name.
- **trxs** original transactions that need to be remove.
- require auth of _self
- require auth of _self or admin

#### lockall
```
void lockall();
```
- set 'active' of global_state false.
- when locked, ibc-transfer and withdraw will not allowed to execute for all token.
- require auth of _self
- require auth of _self or admin

#### unlockall
```
void unlockall();
```
- set 'active' of global_state true.
- when unlocked, the restrictions caused by execute lockall() will be removed.
- require auth of _self
- require auth of _self or admin

#### forceinit
```
Expand All @@ -382,7 +386,7 @@ void unlockall();
so if the number of records in these three tables is greater than 200,
you need to perform this action several times to clear all three tables.
When the console prints "force initialization complete", it says that all three tables have been cleared.
- require auth of _self
- require auth of _self or admin

#### hubinit
```
Expand Down
14 changes: 14 additions & 0 deletions ibc.token/include/ibc.token/ibc.token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ namespace eosio {
[[eosio::action]]
void setglobal( name this_chain, bool active );

[[eosio::action]]
void setadmin( name admin );

[[eosio::action]]
void regpeerchain( name peerchain_name,
string peerchain_info,
Expand Down Expand Up @@ -261,9 +264,18 @@ namespace eosio {
EOSLIB_SERIALIZE( global_state, (this_chain)(active))
};

struct [[eosio::table("admin")]] admin_struct {
name admin;
EOSLIB_SERIALIZE( admin_struct, (admin))
};
typedef eosio::singleton< "admin"_n, admin_struct > admin_singleton;


private:
eosio::singleton< "globals"_n, global_state > _global_state;
global_state _gstate;
eosio::singleton< "admin"_n, admin_struct > _admin_sg;
admin_struct _admin_st;

// code,scope (_self,_self)
struct [[eosio::table("freeaccount")]] peer_chain_free_account {
Expand Down Expand Up @@ -550,6 +562,8 @@ namespace eosio {
void delete_by_hub_trx_id( const transaction_id_type& hub_trx_id ); // when successfully completed
void rollback_hub_trx( const transaction_id_type& hub_trx_id, asset quantity ); // when ibc transmit fails
#endif

void check_admin_auth();
};

} /// namespace eosio
Loading

0 comments on commit 3aba2cb

Please sign in to comment.