diff --git a/cairo/cairo.go b/cairo/cairo.go index 8b530c1..b05c3b7 100644 --- a/cairo/cairo.go +++ b/cairo/cairo.go @@ -62,6 +62,7 @@ func NewCairo(cfg *config.Config) *Cairo { ) cairo.SetInit(cairo) cairo.SetTxnChecker(cairo) + cairo.SetCommitter(cairo) return cairo } @@ -161,6 +162,15 @@ func (c *Cairo) ExecuteTxn(ctx *context.WriteContext) error { return nil } +func (c *Cairo) Commit(block *types.Block) { + blockNumber := uint64(block.Height) + // TODO: set the stateRoot into block + err := c.cairoState.Commit(blockNumber) + if err != nil { + logrus.Errorf("cairo commit failed on Block(%d), error: %v", blockNumber, err) + } +} + func (c *Cairo) Call(ctx *context.ReadContext) { callReq := new(CallRequest) err := ctx.BindJson(callReq) diff --git a/cairo/execution.go b/cairo/execution.go index fc65044..c00a74d 100644 --- a/cairo/execution.go +++ b/cairo/execution.go @@ -11,41 +11,8 @@ import ( "github.com/NethermindEth/juno/utils" "github.com/NethermindEth/juno/vm" "github.com/jinzhu/copier" - "github.com/yu-org/yu/common" - "github.com/yu-org/yu/core/context" - "github.com/yu-org/yu/core/startup" - "github.com/yu-org/yu/core/types" ) -func (c *Cairo) TxnExecute(block *types.Block) error { - - receipts := make(map[common.Hash]*types.Receipt) - - for _, txn := range block.Txns { - wrCall := txn.Raw.WrCall - ctx, err := context.NewWriteContext(txn, block) - if err != nil { - return err - } - wr, err := startup.Land.GetWriting(wrCall.TripodName, wrCall.FuncName) - if err != nil { - return err - } - err = wr(ctx) - rcpt := types.NewReceipt(ctx.Events, err, ctx.Extra) - rcpt.FillMetadata(block, txn, ctx.LeiCost) - receipts[txn.TxnHash] = rcpt - } - blockNumber := uint64(block.Height) - - // commit cairoState - err := c.cairoState.Commit(blockNumber) - if err != nil { - return err - } - return c.TxDB.SetReceipts(receipts) -} - func (c *Cairo) execute( txns []core.Transaction, declaredClasses []core.Class, blockNumber, blockTimestamp uint64, paidFeesOnL1 []*felt.Felt, diff --git a/cmd/node/app/app.go b/cmd/node/app/app.go index f710de8..afaae0a 100644 --- a/cmd/node/app/app.go +++ b/cmd/node/app/app.go @@ -26,6 +26,5 @@ func InitItachi(poaCfg *poa.PoaConfig, crCfg *config.Config) *kernel.Kernel { chain := startup.InitDefaultKernel( poaTri, cairoTri, ) - chain.WithExecuteFn(cairoTri.TxnExecute) return chain } diff --git a/go.mod b/go.mod index 466490a..5bb8ba7 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/sirupsen/logrus v1.9.0 github.com/sourcegraph/conc v0.2.0 github.com/stretchr/testify v1.8.4 - github.com/yu-org/yu v0.0.0-20240417131451-b019a027c6fe + github.com/yu-org/yu v0.0.0-20240423072621-5e66abd97de5 ) require ( diff --git a/go.sum b/go.sum index d24b730..0ae2200 100644 --- a/go.sum +++ b/go.sum @@ -721,6 +721,12 @@ github.com/yu-org/yu v0.0.0-20240416111537-b95d87718178 h1:/4JuKSLlegvz48ZUGi2dC github.com/yu-org/yu v0.0.0-20240416111537-b95d87718178/go.mod h1:W2qfPLdMEmzOymqCFxb3vN+fjZT94CoWPCVPtpgxwdo= github.com/yu-org/yu v0.0.0-20240417131451-b019a027c6fe h1:NQOGZmCtv2+yLfa79ZZ+KAI3O3OqKkGvvxKAaZ18WuA= github.com/yu-org/yu v0.0.0-20240417131451-b019a027c6fe/go.mod h1:W2qfPLdMEmzOymqCFxb3vN+fjZT94CoWPCVPtpgxwdo= +github.com/yu-org/yu v0.0.0-20240418103134-fa12aa88612c h1:+oylS0zlSwJot31dXN8zM65CbevEvW3zzzBtxcQ5CWg= +github.com/yu-org/yu v0.0.0-20240418103134-fa12aa88612c/go.mod h1:W2qfPLdMEmzOymqCFxb3vN+fjZT94CoWPCVPtpgxwdo= +github.com/yu-org/yu v0.0.0-20240422072502-143af323b6bf h1:2/SeagqLp3lDK9ZdW2GqbBStzN9RVthRiqim9WLEoDk= +github.com/yu-org/yu v0.0.0-20240422072502-143af323b6bf/go.mod h1:W2qfPLdMEmzOymqCFxb3vN+fjZT94CoWPCVPtpgxwdo= +github.com/yu-org/yu v0.0.0-20240423072621-5e66abd97de5 h1:rzEPqGLOqubLLjYVJ+BJ/arEjqhaEtnUJOIIVIMgURk= +github.com/yu-org/yu v0.0.0-20240423072621-5e66abd97de5/go.mod h1:W2qfPLdMEmzOymqCFxb3vN+fjZT94CoWPCVPtpgxwdo= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=