Skip to content

Commit

Permalink
Fix: lazy storage diff parsing (#1019)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Jun 2, 2024
1 parent 6fce04b commit e7e250f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/parsers/operations/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (p Transaction) Parse(ctx context.Context, data noderpc.Operation, store pa
}
}

func (p Transaction) parseSmartRollupParams(data noderpc.Operation, tx *operation.Operation) error {
func (p Transaction) parseSmartRollupParams(_ noderpc.Operation, tx *operation.Operation) error {
if len(tx.Parameters) == 0 {
return tx.Entrypoint.Set(consts.DefaultEntrypoint)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/parsers/protocols/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (m Migration) contractMigrations(
return nil
}

func (m Migration) vestingMigration(ctx context.Context, tx models.Transaction, head noderpc.Header, currentProtocol protocol.Protocol) error {
func (m Migration) vestingMigration(ctx context.Context, _ models.Transaction, head noderpc.Header, currentProtocol protocol.Protocol) error {
addresses, err := m.ctx.RPC.GetContractsByBlock(ctx, head.Level)
if err != nil {
return err
Expand Down
22 changes: 16 additions & 6 deletions internal/parsers/storage/lazy_babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type LazyBabylon struct {

ptrMap map[int64]int64
temporaryPointers map[int64]*ast.BigMap
allocated map[int64]struct{}
}

// NewLazyBabylon -
Expand All @@ -33,6 +34,7 @@ func NewLazyBabylon(repo bigmapdiff.Repository, operations operation.Repository,

ptrMap: make(map[int64]int64),
temporaryPointers: make(map[int64]*ast.BigMap),
allocated: make(map[int64]struct{}),
}
}

Expand Down Expand Up @@ -123,6 +125,9 @@ func (b *LazyBabylon) checkPointers(result *noderpc.OperationResult, storage *as
if ptr < 0 {
continue
}
if _, ok := b.temporaryPointers[ptr]; ok {
continue
}

default:
ptr := lsd.ID
Expand All @@ -135,6 +140,9 @@ func (b *LazyBabylon) checkPointers(result *noderpc.OperationResult, storage *as
if ptr < 0 {
continue
}
if _, ok := b.temporaryPointers[ptr]; ok {
continue
}

}
return ErrUnknownTemporaryPointer
Expand Down Expand Up @@ -281,6 +289,7 @@ func (b *LazyBabylon) handleBigMapDiffAlloc(ctx context.Context, diff *noderpc.L
if ptr > -1 {
operation.BigMapActions = append(operation.BigMapActions, b.createBigMapDiffAction("alloc", address, &ptr, nil, operation))
}
b.allocated[ptr] = struct{}{}

return b.handleBigMapDiffUpdate(ctx, diff, ptr, address, operation, store)
}
Expand Down Expand Up @@ -347,19 +356,20 @@ func (b *LazyBabylon) updateTemporaryPointers(src, dst int64) {

func (b *LazyBabylon) getCopyBigMapDiff(ctx context.Context, src int64, address string) (bmd []bigmapdiff.BigMapDiff, err error) {
if src > -1 {
if _, ok := b.allocated[src]; ok {
return b.getDiffsFromUpdates(src)
}
states, err := b.repo.GetByPtr(ctx, address, src)
if err != nil {
return nil, err
}

bmd = make([]bigmapdiff.BigMapDiff, 0, len(states))
for i := range states {
bmd = append(bmd, states[i].ToDiff())
}
} else {
bmd, err = b.getDiffsFromUpdates(src)
if err != nil {
return nil, err
}
return bmd, nil
}
return

return b.getDiffsFromUpdates(src)
}

0 comments on commit e7e250f

Please sign in to comment.