From 16c856f731c42c7aa009ec17c28e53263054ea6a Mon Sep 17 00:00:00 2001 From: zhanjun Date: Tue, 17 Oct 2023 16:23:42 +0800 Subject: [PATCH] feat: migration aspect --- baseapp/abci.go | 34 ++++++++++++++++++++++++++++++++++ simapp/go.mod | 2 +- simapp/go.sum | 1 + tests/go.mod | 2 +- tests/go.sum | 1 + 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 32a6d86832..4d71e32bec 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -4,6 +4,7 @@ import ( "crypto/sha256" "errors" "fmt" + "github.com/artela-network/artelasdk/chaincoreext/scheduler" "os" "sort" "strings" @@ -230,6 +231,18 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc panic(fmt.Errorf("EndBlock listening hook failed, height: %d, err: %w", req.Height, err)) } } + //schedule + if scheduler.TaskInstance() != nil { + confirm, checkErr := scheduler.TaskInstance().Check() + if checkErr != nil { + app.logger.Error( + "scheduler check in EndBlock", + "height", req.Height, + "time", checkErr.Error(), + "confirm", len(confirm), + ) + } + } return res } @@ -284,6 +297,14 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) (resp abci. resp = abci.ResponsePrepareProposal{Txs: req.Txs} } }() + chainID := app.chainID + nonce := uint64(req.Height) // use height as nonce + scheduler.NewTaskManager(req.Height, nonce, chainID) + + scheduledTxs := scheduler.TaskInstance().GetTxs() + for _, scheduledTx := range scheduledTxs { + req.Txs = append(req.Txs, scheduledTx) + } resp = app.prepareProposal(app.prepareProposalState.ctx, req) return resp @@ -343,6 +364,10 @@ func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) (resp abci. } }() + //chainID := app.chainID + //nonce := uint64(req.Height) // use height as nonce + //scheduler.NewTaskManager(req.Height, nonce, chainID) + resp = app.processProposal(app.processProposalState.ctx, req) return resp } @@ -412,6 +437,15 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliv return sdkerrors.ResponseDeliverTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, sdk.MarkEventsToIndex(anteEvents, app.indexEvents), app.trace) } + // scheduler remove + if scheduler.TaskInstance() != nil { + scheduleErr := scheduler.TaskInstance().Remove(req.Tx) + if scheduleErr != nil { + resultStr = "failed" + return sdkerrors.ResponseDeliverTxWithEvents(scheduleErr, gInfo.GasWanted, gInfo.GasUsed, sdk.MarkEventsToIndex(anteEvents, app.indexEvents), app.trace) + } + } + return abci.ResponseDeliverTx{ GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints? GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints? diff --git a/simapp/go.mod b/simapp/go.mod index 4cfe419735..46a5516742 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -74,7 +74,7 @@ require ( github.com/golang/glog v1.1.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/golang/snappy v0.0.4 // indirect + github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/orderedcode v0.0.1 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index d2e6ceeab8..cd9a3e042a 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -500,6 +500,7 @@ github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8l github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= diff --git a/tests/go.mod b/tests/go.mod index b778e37155..21f31341e9 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -75,7 +75,7 @@ require ( github.com/golang/glog v1.1.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/golang/snappy v0.0.4 // indirect + github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/orderedcode v0.0.1 // indirect diff --git a/tests/go.sum b/tests/go.sum index f18b04503e..4639eeba34 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -502,6 +502,7 @@ github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8l github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=