Git Product home page Git Product logo

Comments (3)

AlexITC avatar AlexITC commented on July 21, 2024

Finding corrupted rows

The way to find corrupted balances is running this query:

SELECT address, one.available AS one, (two.received - two.spent) AS two
FROM
  (SELECT address, received - spent AS available
  FROM  (
      SELECT address, SUM(value) AS spent
      FROM transaction_inputs
      GROUP BY address
    ) s JOIN
    (
      SELECT address, SUM(value) AS received
      FROM transaction_outputs
      GROUP BY address
    ) r USING (address)
  ) one JOIN balances two USING (address)
WHERE one.available <> (two.received - two.spent);

Fixing the table manually

The way for fixing the table manually is following these steps:

-- 1. Turn the explorer off

-- 2. count number of balances
SELECT COUNT(*)
FROM balances;

-- 3. verify you would write the same amount
SELECT COUNT(*)
FROM
  (
    SELECT address, SUM(value) AS received
    FROM transaction_outputs
    GROUP BY address
  ) r LEFT JOIN (
      SELECT address, SUM(value) AS spent
      FROM transaction_inputs
      GROUP BY address
  ) s USING (address);

-- 4. delete balances, be sure that the explorer is turned off
DELETE FROM balances;

-- 5. insert the balances
INSERT INTO balances
  (
    SELECT address, received, COALESCE(spent, 0) AS spent
    FROM
      (
        SELECT address, SUM(value) AS received
        FROM transaction_outputs
        GROUP BY address
      ) r LEFT JOIN (
          SELECT address, SUM(value) AS spent
          FROM transaction_inputs
          GROUP BY address
      ) s USING (address)
  );

-- 6. verify you have the same amount
SELECT COUNT(*) FROM balances;

-- 7. start the explorer

from block-explorer.

AlexITC avatar AlexITC commented on July 21, 2024

This commit adds a log when updating a row in the balances table and it doesn't matches what is computed from the transaction values: 4d61427.

After releasing this patch, the logs will be monitored to find steps to reproduce the bug.

from block-explorer.

AlexITC avatar AlexITC commented on July 21, 2024

Since the last release (v2018.05.13) which was around 2 weeks ago, the balances hasn't been corrupted, I'm closing the issue and I'll reopen it in case I see it again.

from block-explorer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.