Skip to content

Commit

Permalink
fix: enforce proposal execution per resource (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 authored Jul 10, 2024
1 parent 3c4cbaa commit 49a0777
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions chains/btc/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,33 @@ func (e *Executor) Execute(proposals []*proposal.Proposal) error {
if len(props) == 0 {
return nil
}
resource, ok := e.resources[props[0].Data.ResourceId]
if !ok {
return fmt.Errorf("no address for resource")

propsPerResource := make(map[[32]byte][]*BtcTransferProposal)
for _, prop := range props {
propsPerResource[prop.Data.ResourceId] = append(propsPerResource[prop.Data.ResourceId], prop)
}

p := pool.New().WithErrors()
for resourceID, props := range propsPerResource {
resourceID := resourceID
props := props

p.Go(func() error {
resource, ok := e.resources[resourceID]
if !ok {
return fmt.Errorf("no resource for ID %s", hex.EncodeToString(resourceID[:]))
}

sessionID := fmt.Sprintf("%s-%s", sessionID, hex.EncodeToString(resourceID[:]))
return e.executeResourceProps(props, resource, sessionID)
})
}
return p.Wait()
}

func (e *Executor) executeResourceProps(props []*BtcTransferProposal, resource config.Resource, sessionID string) error {
log.Info().Str("SessionID", sessionID).Msgf("Executing proposals for resource %s", hex.EncodeToString(resource.ResourceID[:]))

tx, utxos, err := e.rawTx(props, resource)
if err != nil {
return err
Expand Down

0 comments on commit 49a0777

Please sign in to comment.