Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::unapplied_transaction_queue Class Reference

#include <unapplied_transaction_queue.hpp>

Public Types

using iterator = unapplied_trx_queue_type::index<by_type>::type::iterator
 

Public Member Functions

void set_max_transaction_queue_size (uint64_t v)
 
bool empty () const
 
size_t size () const
 
void clear ()
 
size_t incoming_size () const
 
transaction_metadata_ptr get_trx (const transaction_id_type &id) const
 
template<typename Yield , typename Callback >
bool clear_expired (const time_point &pending_block_time, Yield &&yield, Callback &&callback)
 
void clear_applied (const block_state_ptr &bs)
 
void add_forked (const branch_type &forked_branch)
 
void add_aborted (std::vector< transaction_metadata_ptr > aborted_trxs)
 
void add_persisted (const transaction_metadata_ptr &trx)
 
void add_incoming (const transaction_metadata_ptr &trx, bool persist_until_expired, bool return_failure_trace, next_func_t next)
 
iterator begin ()
 
iterator end ()
 
iterator unapplied_begin ()
 
iterator unapplied_end ()
 
iterator persisted_begin ()
 
iterator persisted_end ()
 
iterator incoming_begin ()
 
iterator incoming_end ()
 
iterator erase (iterator itr)
 caller's responsibility to call next() if applicable
 

Detailed Description

Track unapplied transactions for persisted, forked blocks, and aborted blocks. Persisted are first so that they can be applied in each block until expired.

Definition at line 52 of file unapplied_transaction_queue.hpp.

Member Typedef Documentation

◆ iterator

using sysio::chain::unapplied_transaction_queue::iterator = unapplied_trx_queue_type::index<by_type>::type::iterator

Definition at line 195 of file unapplied_transaction_queue.hpp.

Member Function Documentation

◆ add_aborted()

void sysio::chain::unapplied_transaction_queue::add_aborted ( std::vector< transaction_metadata_ptr > aborted_trxs)
inline

Definition at line 156 of file unapplied_transaction_queue.hpp.

156 {
157 for( auto& trx : aborted_trxs ) {
158 fc::time_point expiry = trx->packed_trx()->expiration();
159 auto insert_itr = queue.insert( { std::move( trx ), expiry, trx_enum_type::aborted } );
160 if( insert_itr.second ) added( insert_itr.first );
161 }
162 }
Here is the caller graph for this function:

◆ add_forked()

void sysio::chain::unapplied_transaction_queue::add_forked ( const branch_type & forked_branch)
inline

Definition at line 143 of file unapplied_transaction_queue.hpp.

143 {
144 // forked_branch is in reverse order
145 for( auto ritr = forked_branch.rbegin(), rend = forked_branch.rend(); ritr != rend; ++ritr ) {
146 const block_state_ptr& bsptr = *ritr;
147 for( auto itr = bsptr->trxs_metas().begin(), end = bsptr->trxs_metas().end(); itr != end; ++itr ) {
148 const auto& trx = *itr;
149 fc::time_point expiry = trx->packed_trx()->expiration();
150 auto insert_itr = queue.insert( { trx, expiry, trx_enum_type::forked } );
151 if( insert_itr.second ) added( insert_itr.first );
152 }
153 }
154 }
std::shared_ptr< block_state > block_state_ptr
Here is the caller graph for this function:

◆ add_incoming()

void sysio::chain::unapplied_transaction_queue::add_incoming ( const transaction_metadata_ptr & trx,
bool persist_until_expired,
bool return_failure_trace,
next_func_t next )
inline

Definition at line 179 of file unapplied_transaction_queue.hpp.

179 {
180 auto itr = queue.get<by_trx_id>().find( trx->id() );
181 if( itr == queue.get<by_trx_id>().end() ) {
182 fc::time_point expiry = trx->packed_trx()->expiration();
183 auto insert_itr = queue.insert(
184 { trx, expiry, persist_until_expired ? trx_enum_type::incoming_persisted : trx_enum_type::incoming, return_failure_trace, std::move( next ) } );
185 if( insert_itr.second ) added( insert_itr.first );
186 } else {
187 if( itr->trx_meta == trx ) return; // same trx meta pointer
188 if( next ) {
189 next( std::static_pointer_cast<fc::exception>( std::make_shared<tx_duplicate>(
190 FC_LOG_MESSAGE( info, "duplicate transaction ${id}", ("id", trx->id()) ) ) ) );
191 }
192 }
193 }
#define FC_LOG_MESSAGE(LOG_LEVEL, FORMAT,...)
A helper method for generating log messages.
RUNTIME_API Runtime::ObjectInstance * find(const std::string &name, const IR::ObjectType &type)
uint32_t next(octet_iterator &it, octet_iterator end)
Definition checked.h:137

◆ add_persisted()

void sysio::chain::unapplied_transaction_queue::add_persisted ( const transaction_metadata_ptr & trx)
inline

Definition at line 164 of file unapplied_transaction_queue.hpp.

164 {
165 auto itr = queue.get<by_trx_id>().find( trx->id() );
166 if( itr == queue.get<by_trx_id>().end() ) {
167 fc::time_point expiry = trx->packed_trx()->expiration();
168 auto insert_itr = queue.insert( { trx, expiry, trx_enum_type::persisted } );
169 if( insert_itr.second ) added( insert_itr.first );
170 } else if( itr->trx_type != trx_enum_type::persisted ) {
171 if (itr->trx_type == trx_enum_type::incoming || itr->trx_type == trx_enum_type::incoming_persisted)
172 --incoming_count;
173 queue.get<by_trx_id>().modify( itr, [](auto& un){
174 un.trx_type = trx_enum_type::persisted;
175 } );
176 }
177 }

◆ begin()

iterator sysio::chain::unapplied_transaction_queue::begin ( )
inline

Definition at line 197 of file unapplied_transaction_queue.hpp.

197{ return queue.get<by_type>().begin(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void sysio::chain::unapplied_transaction_queue::clear ( )
inline

Definition at line 85 of file unapplied_transaction_queue.hpp.

85 {
86 queue.clear();
87 }

◆ clear_applied()

void sysio::chain::unapplied_transaction_queue::clear_applied ( const block_state_ptr & bs)
inline

Definition at line 124 of file unapplied_transaction_queue.hpp.

124 {
125 if( empty() ) return;
126 auto& idx = queue.get<by_trx_id>();
127 for( const auto& receipt : bs->block->transactions ) {
128 if( std::holds_alternative<packed_transaction>(receipt.trx) ) {
129 const auto& pt = std::get<packed_transaction>(receipt.trx);
130 auto itr = idx.find( pt.id() );
131 if( itr != idx.end() ) {
132 if( itr->next ) {
133 itr->next( std::static_pointer_cast<fc::exception>( std::make_shared<tx_duplicate>(
134 FC_LOG_MESSAGE( info, "duplicate transaction ${id}", ("id", itr->trx_meta->id())))));
135 }
136 removed( itr );
137 idx.erase( itr );
138 }
139 }
140 }
141 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_expired()

template<typename Yield , typename Callback >
bool sysio::chain::unapplied_transaction_queue::clear_expired ( const time_point & pending_block_time,
Yield && yield,
Callback && callback )
inline

Definition at line 100 of file unapplied_transaction_queue.hpp.

100 {
101 auto& persisted_by_expiry = queue.get<by_expiry>();
102 while( !persisted_by_expiry.empty() ) {
103 const auto& itr = persisted_by_expiry.begin();
104 if( itr->expiry > pending_block_time ) {
105 break;
106 }
107 if( yield() ) {
108 return false;
109 }
110 callback( itr->trx_meta->packed_trx(), itr->trx_type );
111 if( itr->next ) {
112 itr->next( std::static_pointer_cast<fc::exception>(
113 std::make_shared<expired_tx_exception>(
114 FC_LOG_MESSAGE( error, "expired transaction ${id}, expiration ${e}, block time ${bt}",
115 ("id", itr->id())("e", itr->trx_meta->packed_trx()->expiration())
116 ("bt", pending_block_time) ) ) ) );
117 }
118 removed( itr );
119 persisted_by_expiry.erase( itr );
120 }
121 return true;
122 }
thread_local yield_t yield
Definition yield.hpp:52
Here is the caller graph for this function:

◆ empty()

bool sysio::chain::unapplied_transaction_queue::empty ( ) const
inline

Definition at line 77 of file unapplied_transaction_queue.hpp.

77 {
78 return queue.empty();
79 }
Here is the caller graph for this function:

◆ end()

iterator sysio::chain::unapplied_transaction_queue::end ( )
inline

Definition at line 198 of file unapplied_transaction_queue.hpp.

198{ return queue.get<by_type>().end(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase()

iterator sysio::chain::unapplied_transaction_queue::erase ( iterator itr)
inline

Definition at line 211 of file unapplied_transaction_queue.hpp.

211 {
212 removed( itr );
213 return queue.get<by_type>().erase( itr );
214 }
iterator erase(iterator itr)
caller's responsibility to call next() if applicable
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_trx()

transaction_metadata_ptr sysio::chain::unapplied_transaction_queue::get_trx ( const transaction_id_type & id) const
inline

Definition at line 93 of file unapplied_transaction_queue.hpp.

93 {
94 auto itr = queue.get<by_trx_id>().find( id );
95 if( itr == queue.get<by_trx_id>().end() ) return {};
96 return itr->trx_meta;
97 }
Here is the caller graph for this function:

◆ incoming_begin()

iterator sysio::chain::unapplied_transaction_queue::incoming_begin ( )
inline

Definition at line 207 of file unapplied_transaction_queue.hpp.

207{ return queue.get<by_type>().lower_bound( trx_enum_type::incoming_persisted ); }
Here is the caller graph for this function:

◆ incoming_end()

iterator sysio::chain::unapplied_transaction_queue::incoming_end ( )
inline

Definition at line 208 of file unapplied_transaction_queue.hpp.

208{ return queue.get<by_type>().end(); } // if changed to upper_bound, verify usage performance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ incoming_size()

size_t sysio::chain::unapplied_transaction_queue::incoming_size ( ) const
inline

Definition at line 89 of file unapplied_transaction_queue.hpp.

89 {
90 return incoming_count;
91 }
Here is the caller graph for this function:

◆ persisted_begin()

iterator sysio::chain::unapplied_transaction_queue::persisted_begin ( )
inline

Definition at line 204 of file unapplied_transaction_queue.hpp.

204{ return queue.get<by_type>().lower_bound( trx_enum_type::persisted ); }
Here is the caller graph for this function:

◆ persisted_end()

iterator sysio::chain::unapplied_transaction_queue::persisted_end ( )
inline

Definition at line 205 of file unapplied_transaction_queue.hpp.

205{ return queue.get<by_type>().upper_bound( trx_enum_type::persisted ); }
Here is the caller graph for this function:

◆ set_max_transaction_queue_size()

void sysio::chain::unapplied_transaction_queue::set_max_transaction_queue_size ( uint64_t v)
inline

Definition at line 75 of file unapplied_transaction_queue.hpp.

75{ max_transaction_queue_size = v; }

◆ size()

size_t sysio::chain::unapplied_transaction_queue::size ( ) const
inline

Definition at line 81 of file unapplied_transaction_queue.hpp.

81 {
82 return queue.size();
83 }
Here is the caller graph for this function:

◆ unapplied_begin()

iterator sysio::chain::unapplied_transaction_queue::unapplied_begin ( )
inline

Definition at line 201 of file unapplied_transaction_queue.hpp.

201{ return queue.get<by_type>().begin(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unapplied_end()

iterator sysio::chain::unapplied_transaction_queue::unapplied_end ( )
inline

Definition at line 202 of file unapplied_transaction_queue.hpp.

202{ return queue.get<by_type>().upper_bound( trx_enum_type::aborted ); }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: