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

(BIDS-2535) added default methods based on contract state #2830

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 24 additions & 28 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2238,10 +2238,6 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, pageTo
if err != nil {
return nil, fmt.Errorf("error parsing Eth1InternalTransactionIndexed tx index: %v", err)
}
if tx_idx == TX_PER_BLOCK_LIMIT {
// handle "reversePaddedIndex 0"-issue
tx_idx = 0
}
tx_idx = TX_PER_BLOCK_LIMIT - tx_idx
if tx_idx < 0 {
return nil, fmt.Errorf("invalid Eth1InternalTransactionIndexed tx index: %d", tx_idx)
Expand Down Expand Up @@ -2273,11 +2269,10 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, pageTo
if len(contractInteractionTypes) > i {
contractInteraction = contractInteractionTypes[i]
}
method := bigtable.GetMethodLabel(t.MethodId, contractInteraction != types.CONTRACT_NONE)

tableData[i] = []interface{}{
utils.FormatTransactionHash(t.Hash, t.ErrorMsg == ""),
utils.FormatMethod(method),
utils.FormatMethod(bigtable.GetMethodLabel(t.MethodId, contractInteraction)),
utils.FormatBlockNumber(t.BlockNumber),
utils.FormatTimestamp(t.Time.AsTime().Unix()),
utils.FormatAddressWithLimitsInAddressPageTable(address, t.From, fromName, false, digitLimitInAddressPagesTable, nameLimitInAddressPagesTable, true),
Expand Down Expand Up @@ -2666,7 +2661,6 @@ func (bigtable *Bigtable) GetEth1ItxsForAddress(prefix string, limit int64) ([]*
}
}

indexes[len(indexes)-1] = skipBlockIfLastTxIndex(indexes[len(indexes)-1])
return data, indexes, nil
}

Expand Down Expand Up @@ -2706,10 +2700,6 @@ func (bigtable *Bigtable) GetAddressInternalTableData(address []byte, pageToken
if err != nil {
return nil, fmt.Errorf("error parsing Eth1InternalTransactionIndexed tx index: %v", err)
}
if tx_idx == TX_PER_BLOCK_LIMIT {
// handle "reversePaddedIndex 0"-issue
tx_idx = 0
}
tx_idx = TX_PER_BLOCK_LIMIT - tx_idx
if tx_idx < 0 {
return nil, fmt.Errorf("invalid Eth1InternalTransactionIndexed tx index: %d", tx_idx)
Expand All @@ -2719,10 +2709,6 @@ func (bigtable *Bigtable) GetAddressInternalTableData(address []byte, pageToken
if err != nil {
return nil, fmt.Errorf("error parsing Eth1InternalTransactionIndexed trace index: %v", err)
}
if trace_idx == ITX_PER_TX_LIMIT {
// handle "reversePaddedIndex 0"-issue
trace_idx = 0
}
trace_idx = ITX_PER_TX_LIMIT - trace_idx
if tx_idx < 0 {
return nil, fmt.Errorf("invalid Eth1InternalTransactionIndexed trace index: %d", trace_idx)
Expand Down Expand Up @@ -2817,13 +2803,13 @@ func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte,
}

fromName := BigtableClient.GetAddressLabel(names[string(from)], from_contractInteraction)
toName := BigtableClient.GetAddressLabel(names[string(to)], from_contractInteraction)
toName := BigtableClient.GetAddressLabel(names[string(to)], to_contractInteraction)

itx := types.ITransaction{
From: utils.FormatAddress(from, nil, fromName, false, from_contractInteraction != types.CONTRACT_NONE, true),
To: utils.FormatAddress(to, nil, toName, false, to_contractInteraction != types.CONTRACT_NONE, true),
Amount: utils.FormatElCurrency(value, currency, 8, true, false, false, true),
TracePath: utils.FormatTracePath(tx_type, parityTrace[i].TraceAddress, parityTrace[i].Error == "", bigtable.GetMethodLabel(input, true)),
TracePath: utils.FormatTracePath(tx_type, parityTrace[i].TraceAddress, parityTrace[i].Error == "", bigtable.GetMethodLabel(input, from_contractInteraction)),
Advanced: tx_type == "delegatecall" || string(value) == "\x00",
}

Expand Down Expand Up @@ -4593,24 +4579,34 @@ func (bigtable *Bigtable) GetSignature(hex string, st types.SignatureType) (*str
}

// get a method label for its byte signature with defaults
func (bigtable *Bigtable) GetMethodLabel(id []byte, invokesContract bool) string {
method := "Transfer"
if len(id) > 0 {
if invokesContract {
method = fmt.Sprintf("0x%x", id)
func (bigtable *Bigtable) GetMethodLabel(data []byte, interaction types.ContractInteractionType) string {
id := data
if len(data) > 3 {
id = data[:4]
}
method := fmt.Sprintf("0x%x", id)

switch interaction {
case types.CONTRACT_NONE:
return "Transfer"
case types.CONTRACT_CREATION:
return "Constructor"
case types.CONTRACT_DESTRUCTION:
return "Destruction"
Comment on lines +4593 to +4595
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Constructor and Destruction are not the same type of word.
If we want to leave it like that it is also fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean, but I think this is okay because developers can decide how a smart contract is constructed, while that's not possible for destruction. I chose that wording to highlight that difference, but it's not a very strong opinion either.

case types.CONTRACT_PRESENT:
if len(id) == 4 {
cacheKey := fmt.Sprintf("M:H2L:%s", method)
if _, err := cache.TieredCache.GetWithLocalTimeout(cacheKey, time.Hour, &method); err != nil {
sig, err := bigtable.GetSignature(method, types.MethodSignature)
if err == nil {
if sig, err := bigtable.GetSignature(method, types.MethodSignature); err == nil {
cache.TieredCache.Set(cacheKey, method, time.Hour)
Eisei24 marked this conversation as resolved.
Show resolved Hide resolved
if sig != nil {
method = utils.RemoveRoundBracketsIncludingContent(*sig)
return utils.RemoveRoundBracketsIncludingContent(*sig)
}
cache.TieredCache.Set(cacheKey, method, time.Hour)
}
}
} else {
method = "Transfer*"
}
default:
utils.LogError(nil, "unknown contract interaction type", 0, map[string]interface{}{"type": interaction})
}
return method
}
Expand Down
12 changes: 1 addition & 11 deletions handlers/eth1Block.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,6 @@ func GetExecutionBlockPageData(number uint64, limit int) (*types.Eth1BlockPageDa
tx.To = tx.ContractAddress
}

method := "Transfer"
{
d := tx.GetData()
if len(d) > 3 {
m := d[:4]
invokesContract := len(tx.GetItx()) > 0 || tx.GetGasUsed() > 21000 || tx.GetErrorMsg() != ""
method = db.BigtableClient.GetMethodLabel(m, invokesContract)
}
}

var contractInteraction types.ContractInteractionType
if len(contractInteractionTypes) > i {
contractInteraction = contractInteractionTypes[i]
Expand All @@ -208,7 +198,7 @@ func GetExecutionBlockPageData(number uint64, limit int) (*types.Eth1BlockPageDa
Value: new(big.Int).SetBytes(tx.Value),
Fee: txFee,
GasPrice: effectiveGasPrice,
Method: method,
Method: db.BigtableClient.GetMethodLabel(tx.GetData(), contractInteraction),
})
}

Expand Down
11 changes: 1 addition & 10 deletions handlers/eth1Transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ func getTransactionDataStartingWithPageToken(pageToken string) *types.DataTableR
for i := len(t) - 1; i >= 0; i-- {
v := t[i]
wg.Go(func() error {
method := "Transfer"
{
d := v.GetData()
if len(d) > 3 {
m := d[:4]
invokesContract := len(v.GetItx()) > 0 || v.GetGasUsed() > 21000 || v.GetErrorMsg() != ""
method = db.BigtableClient.GetMethodLabel(m, invokesContract)
}
}
if v.GetTo() == nil {
v.To = v.ContractAddress
}
Expand All @@ -108,7 +99,7 @@ func getTransactionDataStartingWithPageToken(pageToken string) *types.DataTableR
}
tableData = append(tableData, []interface{}{
utils.FormatAddressWithLimits(v.GetHash(), "", false, "tx", visibleDigitsForHash+5, 18, true),
utils.FormatMethod(method),
utils.FormatMethod(db.BigtableClient.GetMethodLabel(v.GetData(), contractInteraction)),
template.HTML(fmt.Sprintf(`<A href="block/%d">%v</A>`, b.GetNumber(), utils.FormatAddCommas(b.GetNumber()))),
utils.FormatTimestamp(b.GetTime().AsTime().Unix()),
utils.FormatAddressWithLimits(v.GetFrom(), names[string(v.GetFrom())], false, "address", visibleDigitsForHash+5, 18, true),
Expand Down
Loading