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

Invalid method is returned #1277

Closed
Keith-CY opened this issue Jan 12, 2023 · 9 comments
Closed

Invalid method is returned #1277

Keith-CY opened this issue Jan 12, 2023 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@Keith-CY
Copy link
Member

Keith-CY commented Jan 12, 2023

1、This is a plain transaction to send pCKB https://v1.testnet.gwscan.com/tx/0xbccc4daef54ec6fd5cdafd893efbf311c0640d0280e580b4aedfc852d8c7ded8

The method is expected to be null, but 0x00 is received.

2、The contract has an ABI, but the standard method parsing exception in the transaction list.
https://v1.testnet.gwscan.com/account/0xdac77963b2c03c666be8b64b4e41b7fc2af3d8f0?tab=transactions
Image
https://v1.testnet.gwscan.com/nft-collection/0xdac77963b2c03c666be8b64b4e41b7fc2af3d8f0
Image

@Keith-CY
Copy link
Member Author

It's an online bug, how is it going @Naupio

@Naupio
Copy link
Contributor

Naupio commented Jan 30, 2023

link pr #1298

@Naupio
Copy link
Contributor

Naupio commented Jan 30, 2023

this issue need to process history date of transactions table which method id is "0x00"

@Keith-CY Keith-CY moved this from In Progress to QA in Nervos Wallet/Explorer Feb 1, 2023
@Keith-CY Keith-CY moved this from QA to In Progress in Nervos Wallet/Explorer Feb 1, 2023
@Naupio
Copy link
Contributor

Naupio commented Feb 1, 2023

process update "0x00" transaction history data script

defmodule Temp do
  alias GodwokenExplorer.Repo
  alias GodwokenExplorer.Transaction
  alias GodwokenExplorer.Chain.Data

  alias GodwokenExplorer.Chain.Import

  import GodwokenRPC.Util, only: [import_timestamps: 0]
  import Ecto.Query

  def fix_transaction_method_id() do
    {:ok, mid} = Data.cast("0x00")

    q =
      from(t in Transaction,
        where: t.method_id == ^mid
      )

    need_process = q |> Repo.aggregate(:count) |> IO.inspect(label: "need process")
    loop = round(need_process / 500) + 1

    Enum.reduce(1..loop, 0, fn _, acc ->
      params =
        q
        |> limit(500)
        |> Repo.all()
        |> Enum.map(fn p ->
          Map.from_struct(p)
          |> Map.delete(:__meta__)
          |> Map.put(:method_id, nil)
        end)

      add_acc = length(params)

      Import.insert_changes_list(
        params,
        for: Transaction,
        timestamps: import_timestamps(),
        on_conflict: {:replace, [:method_id]},
        conflict_target: [:hash]
      )

      (acc + add_acc) |> IO.inspect(label: "processed")
    end)
  end
end

@Naupio
Copy link
Contributor

Naupio commented Feb 1, 2023

testnet-stg history was proceed

@Naupio
Copy link
Contributor

Naupio commented Feb 2, 2023

need fixed method name with task

defmodule Temp do

  import Ecto.Query

  import GodwokenRPC.Util,
    only: [
      import_timestamps: 0
    ]

  alias GodwokenExplorer.Chain.{Import}
  alias GodwokenExplorer.{Repo, Account, Transaction, SmartContract, Polyjuice}

  def do_perform() do
    return1 = common_base_query() |> process_order_by_limit() |> Repo.all()
    batch_update_transaction_method_id_name(return1)

    # check method name if smart_contract abi update later
    return2 =
      check_method_name_query()
      |> process_order_by_limit()
      |> Repo.all()

    batch_update_transaction_method_id_name(return2)
    {:ok, nil}
  end

  def batch_update_transaction_method_id_name(return) do
    IO.inspect(length(return), label: "need update transaction count ===>")
    concurrency = 500

    result =
      return
      |> Enum.chunk_every(concurrency)
      |> Enum.reduce(0, fn maps, acc ->
        return =
          maps
          |> Task.async_stream(
            fn map ->
              {method_id, method_name} =
                with input when not is_nil(input) <- map.input,
                     input <- input |> to_string(),
                     mid <- input |> String.slice(0, 10),
                     true <- String.length(mid) >= 10 do
                  method_name =
                    Polyjuice.get_method_name_without_account_check(
                      map.to_account_id,
                      input |> to_string
                    )

                  {mid, method_name}
                else
                  _ ->
                    {nil, nil}
                end

              map
              |> Map.delete(:input)
              |> Map.put(:method_id, method_id)
              |> Map.put(:method_name, method_name)
            end,
            timeout: :infinity
          )
          |> Enum.map(fn {:ok, r} -> r end)
          |> Enum.filter(fn r -> not is_nil(r.method_id) end)

        Import.insert_changes_list(return,
          for: Transaction,
          timestamps: import_timestamps(),
          on_conflict: {:replace, [:method_id, :method_name]},
          conflict_target: :hash
        )

        IO.inspect(acc + length(return), label: "data was processed ==>")
      end)

    {:ok, result}
  end

  def common_base_query() do
    common_query()
    |> where([transaction: t], is_nil(t.method_id))
  end

  defp common_query() do
    from(t in Transaction,
      as: :transaction,
      inner_join: sc in SmartContract,
      on: t.to_account_id == sc.account_id,
      as: :smart_contract,
      inner_join: a in Account,
      as: :account,
      on: a.id == t.to_account_id,
      where: a.type == :polyjuice_contract,
      inner_join: p in Polyjuice,
      as: :polyjuice,
      on: t.hash == p.tx_hash,
      where: p.input_size >= 10,
      select: %{
        hash: t.hash,
        from_account_id: t.from_account_id,
        to_account_id: t.to_account_id,
        nonce: t.nonce,
        args: t.args,
        input: p.input
      }
    )
  end

  def check_method_name_query() do
    common_query()
    |> where([transaction: t], not is_nil(t.method_id) and is_nil(t.method_name))
    |> where(
      [smart_contract: sc],
      not is_nil(sc.abi)
    )
  end

  def process_order_by_limit(query) do
    query
    |> order_by([transaction: t], desc: t.updated_at)
    |> limit(10000)
  end
end

@Naupio
Copy link
Contributor

Naupio commented Feb 2, 2023

pr link #1305

@Naupio Naupio moved this from In Progress to QA in Nervos Wallet/Explorer Feb 2, 2023
@Naupio
Copy link
Contributor

Naupio commented Feb 7, 2023

testnet-prod was deployed @FrederLu

@FrederLu
Copy link

FrederLu commented Feb 7, 2023

Verified.

@FrederLu FrederLu moved this from QA to Production in Nervos Wallet/Explorer Feb 7, 2023
@Danie0918 Danie0918 moved this to ✅ Done in Layer2 Explorer Feb 26, 2023
@Naupio Naupio closed this as completed Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Status: Production
Development

No branches or pull requests

3 participants