Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change cell hash to message hash #543

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions pkg/api/emulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ func (h *Handler) addToMempool(ctx context.Context, bytesBoc []byte, shardAccoun
core.Visit(trace, func(node *core.Trace) {
accounts[node.Account] = struct{}{}
})
hash, err := msgCell[0].Hash256()
if err != nil {
return shardAccount, err
}
h.mempoolEmulate.traces.Set(hash, trace, cache.WithExpiration(time.Second*time.Duration(ttl)))
h.mempoolEmulate.traces.Set(ton.Bits256(message.Hash()), trace, cache.WithExpiration(time.Second*time.Duration(ttl)))
var localMessageHashCache = make(map[ton.Bits256]bool)
for account := range accounts {
if _, ok := h.mempoolEmulateIgnoreAccounts[account]; ok { // the map is filled only once at the start
Expand All @@ -166,7 +162,7 @@ func (h *Handler) addToMempool(ctx context.Context, bytesBoc []byte, shardAccoun
newMemHashes = append(newMemHashes, mHash)
}
}
newMemHashes = append(newMemHashes, hash) // it's important to make it last
newMemHashes = append(newMemHashes, ton.Bits256(message.Hash())) // it's important to make it last
h.mempoolEmulate.accountsTraces.Set(account, newMemHashes, cache.WithExpiration(time.Second*time.Duration(ttl)))
}
emulationCh <- blockchain.ExtInMsgCopy{
Expand Down
26 changes: 8 additions & 18 deletions pkg/api/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,12 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
if err != nil {
return nil, toError(http.StatusBadRequest, err)
}
hash, err := c.Hash256()
if err != nil {
var message tlb.Message
if err = tlb.Unmarshal(c, &message); err != nil {
return nil, toError(http.StatusBadRequest, err)
}
trace, prs := h.mempoolEmulate.traces.Get(hash)
trace, prs := h.mempoolEmulate.traces.Get(ton.Bits256(message.Hash()))
if !prs {
var m tlb.Message
if err := tlb.Unmarshal(c, &m); err != nil {
return nil, toError(http.StatusBadRequest, err)
}
configBase64, err := h.storage.TrimmedConfigBase64()
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand All @@ -418,7 +414,7 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
tree, err := emulator.Run(ctx, m)
tree, err := emulator.Run(ctx, message)
if err != nil {
return nil, toProperEmulationError(err)
}
Expand All @@ -444,17 +440,12 @@ func (h *Handler) EmulateMessageToTrace(ctx context.Context, request *oas.Emulat
if err != nil {
return nil, toError(http.StatusBadRequest, err)
}
hash, err := c.Hash256()
if err != nil {
var message tlb.Message
if err = tlb.Unmarshal(c, &message); err != nil {
return nil, toError(http.StatusBadRequest, err)
}
trace, prs := h.mempoolEmulate.traces.Get(hash)
trace, prs := h.mempoolEmulate.traces.Get(ton.Bits256(message.Hash()))
if !prs {
var m tlb.Message
err = tlb.Unmarshal(c, &m)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
}
configBase64, err := h.storage.TrimmedConfigBase64()
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand All @@ -466,12 +457,11 @@ func (h *Handler) EmulateMessageToTrace(ctx context.Context, request *oas.Emulat
if !params.IgnoreSignatureCheck.Value {
options = append(options, txemulator.WithSignatureCheck())
}

emulator, err := txemulator.NewTraceBuilder(options...)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
tree, err := emulator.Run(ctx, m)
tree, err := emulator.Run(ctx, message)
if err != nil {
return nil, toProperEmulationError(err)
}
Expand Down
Loading