github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/app/app_abci.go (about)

     1  package app
     2  
     3  import (
     4  	"runtime"
     5  	"time"
     6  
     7  	appconfig "github.com/fibonacci-chain/fbc/app/config"
     8  	"github.com/fibonacci-chain/fbc/libs/system/trace"
     9  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
    10  	"github.com/fibonacci-chain/fbc/x/wasm/watcher"
    11  )
    12  
    13  // BeginBlock implements the Application interface
    14  func (app *FBChainApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
    15  	trace.OnAppBeginBlockEnter(app.LastBlockHeight() + 1)
    16  	app.EvmKeeper.Watcher.DelayEraseKey()
    17  	return app.BaseApp.BeginBlock(req)
    18  }
    19  
    20  func (app *FBChainApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
    21  
    22  	trace.OnAppDeliverTxEnter()
    23  
    24  	resp := app.BaseApp.DeliverTx(req)
    25  
    26  	return resp
    27  }
    28  
    29  func (app *FBChainApp) PreDeliverRealTx(req []byte) (res abci.TxEssentials) {
    30  	return app.BaseApp.PreDeliverRealTx(req)
    31  }
    32  
    33  func (app *FBChainApp) DeliverRealTx(req abci.TxEssentials) (res abci.ResponseDeliverTx) {
    34  	trace.OnAppDeliverTxEnter()
    35  	resp := app.BaseApp.DeliverRealTx(req)
    36  	app.EvmKeeper.Watcher.RecordTxAndFailedReceipt(req, &resp, app.GetTxDecoder())
    37  
    38  	return resp
    39  }
    40  
    41  // EndBlock implements the Application interface
    42  func (app *FBChainApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
    43  	return app.BaseApp.EndBlock(req)
    44  }
    45  
    46  // Commit implements the Application interface
    47  func (app *FBChainApp) Commit(req abci.RequestCommit) abci.ResponseCommit {
    48  	if gcInterval := appconfig.GetFecConfig().GetGcInterval(); gcInterval > 0 {
    49  		if (app.BaseApp.LastBlockHeight()+1)%int64(gcInterval) == 0 {
    50  			startTime := time.Now()
    51  			runtime.GC()
    52  			elapsed := time.Now().Sub(startTime).Milliseconds()
    53  			app.Logger().Info("force gc for debug", "height", app.BaseApp.LastBlockHeight()+1,
    54  				"elapsed(ms)", elapsed)
    55  		}
    56  	}
    57  	//defer trace.GetTraceSummary().Dump()
    58  	defer trace.OnCommitDone()
    59  
    60  	// reload upgrade info for upgrade proposal
    61  	//app.setupUpgradeModules()
    62  	tasks := app.heightTasks[app.BaseApp.LastBlockHeight()+1]
    63  	if tasks != nil {
    64  		ctx := app.BaseApp.GetDeliverStateCtx()
    65  		for _, t := range *tasks {
    66  			if err := t.Execute(ctx); nil != err {
    67  				panic("bad things")
    68  			}
    69  		}
    70  	}
    71  	res := app.BaseApp.Commit(req)
    72  
    73  	// we call watch#Commit here ,because
    74  	// 1. this round commit a valid block
    75  	// 2. before commit the block,State#updateToState hasent not called yet,so the proposalBlockPart is not nil which means we wont
    76  	// 	  call the prerun during commit step(edge case)
    77  	app.EvmKeeper.Watcher.Commit()
    78  	watcher.Commit()
    79  
    80  	return res
    81  }