Skip to content

Commit

Permalink
upgrade yu for commit (#54)
Browse files Browse the repository at this point in the history
* use yu commit

* upgrade

* clean comments
  • Loading branch information
Lawliet-Chan authored Apr 23, 2024
1 parent 8ebefd3 commit 2d59ad4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 35 deletions.
10 changes: 10 additions & 0 deletions cairo/cairo.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func NewCairo(cfg *config.Config) *Cairo {
)
cairo.SetInit(cairo)
cairo.SetTxnChecker(cairo)
cairo.SetCommitter(cairo)

return cairo
}
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 0 additions & 33 deletions cairo/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion cmd/node/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 2d59ad4

Please sign in to comment.