Skip to content

Commit

Permalink
(BIDS-2550) detect failed transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
remoterami committed Nov 6, 2023
1 parent 92b6eba commit ba72047
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 214 deletions.
29 changes: 20 additions & 9 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ func (bigtable *Bigtable) TransformItx(blk *types.Eth1Block, cache *freecache.Ca
if idx.GetType() == "create" || idx.GetType() == "suicide" {
contractUpdate := &types.IsContractUpdate{
IsContract: idx.GetType() == "create",
Success: idx.GetErrorMsg() == "",
}
b, err := proto.Marshal(contractUpdate)
if err != nil {
Expand Down Expand Up @@ -2767,12 +2768,14 @@ func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte,
keys := make([]int, 0, len(transfers))
itransactions := make([]*types.Eth1InternalTransactionIndexed, 0, len(transfers))
idxs := make([][2]int64, 0, len(transfers))
for k, v := range transfers {
for k := range transfers {
keys = append(keys, k)
itransactions = append(itransactions, v)
idxs = append(idxs, [2]int64{int64(txIdx), int64(k)})
}
sort.Ints(keys)
for _, i := range keys {
itransactions = append(itransactions, transfers[i])
idxs = append(idxs, [2]int64{int64(txIdx), int64(i)})
}

txIsContractList, err := BigtableClient.GetAddressIsContractAtTransaction(itransactions, idxs)
if err != nil {
Expand Down Expand Up @@ -3730,7 +3733,7 @@ func (bigtable *Bigtable) GetAddressNames(addresses map[string]string) error {
}

type isContractInfo struct {
update bool
update *types.IsContractUpdate
ts gcp_bigtable.Timestamp
}

Expand Down Expand Up @@ -3763,14 +3766,14 @@ func (bigtable *Bigtable) getAddressIsContractHistories(histories map[string][]i

keyPrefix := fmt.Sprintf("%s:", bigtable.chainId)
err := bigtable.tableMetadata.ReadRows(ctx, gcp_bigtable.RowList(keys), func(row gcp_bigtable.Row) bool {
b := &types.IsContractUpdate{}
address := strings.TrimPrefix(row.Key(), keyPrefix)
for _, v := range row[ACCOUNT_METADATA_FAMILY] {
b := &types.IsContractUpdate{}
err := proto.Unmarshal(v.Value, b)
if err != nil {
utils.LogError(err, "error parsing IsContractUpdate data", 0)
}
histories[address] = append(histories[address], isContractInfo{update: b.IsContract, ts: v.Timestamp})
histories[address] = append(histories[address], isContractInfo{update: b, ts: v.Timestamp})
}

return true
Expand Down Expand Up @@ -3826,11 +3829,19 @@ func (bigtable *Bigtable) GetAddressIsContractAt(requests []isContractAtRequest)

if exact_match {
results[i] = types.CONTRACT_DESTRUCTION
if history[k].update {
if history[k].update.IsContract {
results[i] = types.CONTRACT_CREATION
}
} else if history[k].update {
results[i] = types.CONTRACT_PRESENT
} else {
// find first successful prev update
for j := k; j >= 0; j-- {
if history[j].update.Success {
if history[j].update.IsContract {
results[i] = types.CONTRACT_PRESENT
}
break
}
}
}
}
return results, nil
Expand Down
Loading

0 comments on commit ba72047

Please sign in to comment.