Skip to content

Commit

Permalink
Fix: sapling state diff
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Mar 18, 2022
1 parent 38b485c commit c3298ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
21 changes: 14 additions & 7 deletions cmd/indexer/indexer/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Receiver struct {

threads chan struct{}
present map[int64]struct{}
mx sync.Mutex
mx sync.RWMutex
wg sync.WaitGroup
}

Expand All @@ -47,14 +47,19 @@ func NewReceiver(rpc noderpc.INode, queueSize, threadsCount int64) *Receiver {

// AddTask -
func (r *Receiver) AddTask(level int64) {
r.mx.Lock()
defer r.mx.Unlock()

r.mx.RLock()
if _, ok := r.present[level]; ok {
r.mx.RUnlock()
return
}
r.present[level] = struct{}{}
r.queue <- level
r.mx.RUnlock()

r.mx.Lock()
{
r.present[level] = struct{}{}
r.queue <- level
}
r.mx.Unlock()
}

// Start -
Expand Down Expand Up @@ -118,7 +123,9 @@ func (r *Receiver) job(level int64) {
r.blocks <- &block

r.mx.Lock()
delete(r.present, level)
{
delete(r.present, level)
}
r.mx.Unlock()
}()
}
6 changes: 6 additions & 0 deletions internal/bcd/ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,12 @@ func TestTypedAst_Diff(t *testing.T) {
curr: `[{"prim":"Pair","args":[{"bytes":"000002"},{"prim":"Some","args":[{"string":"expruN32WETsB2Dx1AynDmMufVr1As9qdnjRxKQ82rk2qZ4uxuKVMK"}]}]}]`,
prev: `[]`,
want: `{"prim":"list","type":"list","name":"@list_1","children":[{"prim":"pair","type":"namedtuple","name":"@pair_2","diff_type":"create","children":[{"prim":"sapling_transaction","type":"sapling_transaction","name":"@sapling_transaction_3","diff_type":"create","value":"000002"},{"prim":"key_hash","type":"key_hash","name":"@key_hash_5","diff_type":"create","value":"expruN32WETsB2Dx1AynDmMufVr1As9qdnjRxKQ82rk2qZ4uxuKVMK"}]}]}`,
}, {
name: "ithacanet/KT1Ndofgeqti5nRHtV96No9RswGm93Efn743/entrypoint_0 sapling state",
tree: `{"prim":"sapling_state","args":[{"int":"8"}]}`,
curr: `{"int":"785"}`,
prev: `{"int":"785"}`,
want: `{"prim":"sapling_state","type":"sapling_state","name":"@sapling_state_1","children":[{"prim":"int","type":"int","name":"@int_0","value":"785"}]}`,
},
}
for _, tt := range tests {
Expand Down
13 changes: 12 additions & 1 deletion internal/bcd/ast/sapling_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,18 @@ func (ss *SaplingState) Distinguish(x Distinguishable) (*MiguelNode, error) {
if !ok {
return nil, nil
}
return ss.Default.Distinguish(&second.Default)

node, err := ss.Default.ToMiguel()
if err != nil {
return nil, err
}
node.Children = make([]*MiguelNode, 0)
child, err := ss.Type.Distinguish(second.Type)
if err != nil {
return nil, err
}
node.Children = append(node.Children, child)
return node, nil
}

// EqualType -
Expand Down

0 comments on commit c3298ab

Please sign in to comment.