@@ -23,6 +23,7 @@ use cnetwork::NetworkService;
23
23
use crossbeam_channel as crossbeam;
24
24
use cstate:: ActionHandler ;
25
25
use ctypes:: machine:: WithBalances ;
26
+ use ctypes:: transaction:: Action ;
26
27
use ctypes:: BlockNumber ;
27
28
use primitives:: H256 ;
28
29
use rlp:: UntrustedRlp ;
@@ -195,13 +196,21 @@ impl ConsensusEngine<CodeChainMachine> for Tendermint {
195
196
196
197
fn on_close_block ( & self , block : & mut ExecutedBlock ) -> Result < ( ) , Error > {
197
198
let author = * block. header ( ) . author ( ) ;
198
- let transactions = block. transactions ( ) . to_owned ( ) . into_iter ( ) ;
199
- let fee = transactions. map ( |tx| tx. fee ) . sum ( ) ;
199
+ let ( total_fee, min_fee) = {
200
+ let transactions = block. transactions ( ) ;
201
+ let total_fee: u64 = transactions. iter ( ) . map ( |tx| tx. fee ) . sum ( ) ;
202
+ let min_fee = transactions. iter ( ) . map ( |tx| self . minimum_fee ( & tx. action ) ) . sum ( ) ;
203
+ ( total_fee, min_fee)
204
+ } ;
205
+ assert ! ( total_fee >= min_fee, "{} >= {}" , total_fee, min_fee) ;
200
206
let stakes = stake:: get_stakes ( block. state ( ) ) . expect ( "Cannot get Stake status" ) ;
201
207
202
- for ( address, share) in stake:: fee_distribute ( & author, fee , & stakes) {
208
+ for ( address, share) in stake:: fee_distribute ( & author, min_fee , & stakes) {
203
209
self . machine . add_balance ( block, & address, share) ?
204
210
}
211
+ if total_fee != min_fee {
212
+ self . machine . add_balance ( block, & author, total_fee - min_fee) ?
213
+ }
205
214
Ok ( ( ) )
206
215
}
207
216
@@ -287,6 +296,62 @@ impl ConsensusEngine<CodeChainMachine> for Tendermint {
287
296
}
288
297
}
289
298
299
+ impl Tendermint {
300
+ fn minimum_fee ( & self , action : & Action ) -> u64 {
301
+ let params = self . machine . params ( ) ;
302
+ match action {
303
+ Action :: MintAsset {
304
+ ..
305
+ } => params. min_asset_mint_cost ,
306
+ Action :: TransferAsset {
307
+ ..
308
+ } => params. min_asset_transfer_cost ,
309
+ Action :: ChangeAssetScheme {
310
+ ..
311
+ } => params. min_asset_scheme_change_cost ,
312
+ Action :: IncreaseAssetSupply {
313
+ ..
314
+ } => params. min_asset_supply_increase_cost ,
315
+ Action :: ComposeAsset {
316
+ ..
317
+ } => params. min_asset_compose_cost ,
318
+ Action :: DecomposeAsset {
319
+ ..
320
+ } => params. min_asset_decompose_cost ,
321
+ Action :: UnwrapCCC {
322
+ ..
323
+ } => params. min_asset_unwrap_ccc_cost ,
324
+ Action :: Pay {
325
+ ..
326
+ } => params. min_pay_transaction_cost ,
327
+ Action :: SetRegularKey {
328
+ ..
329
+ } => params. min_set_regular_key_tranasction_cost ,
330
+ Action :: CreateShard {
331
+ ..
332
+ } => params. min_create_shard_transaction_cost ,
333
+ Action :: SetShardOwners {
334
+ ..
335
+ } => params. min_set_shard_owners_transaction_cost ,
336
+ Action :: SetShardUsers {
337
+ ..
338
+ } => params. min_set_shard_users_transaction_cost ,
339
+ Action :: WrapCCC {
340
+ ..
341
+ } => params. min_wrap_ccc_transaction_cost ,
342
+ Action :: Custom {
343
+ ..
344
+ } => params. min_custom_transaction_cost ,
345
+ Action :: Store {
346
+ ..
347
+ } => params. min_store_transaction_cost ,
348
+ Action :: Remove {
349
+ ..
350
+ } => params. min_remove_transaction_cost ,
351
+ }
352
+ }
353
+ }
354
+
290
355
fn combine_proofs ( signal_number : BlockNumber , set_proof : & [ u8 ] , finality_proof : & [ u8 ] ) -> Vec < u8 > {
291
356
let mut stream = :: rlp:: RlpStream :: new_list ( 3 ) ;
292
357
stream. append ( & signal_number) . append ( & set_proof) . append ( & finality_proof) ;
0 commit comments