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

Ensure compatibility with stellar-core 15.x #207

Open
nebolsin opened this issue Nov 2, 2020 · 0 comments · May be fixed by #209
Open

Ensure compatibility with stellar-core 15.x #207

nebolsin opened this issue Nov 2, 2020 · 0 comments · May be fixed by #209
Assignees

Comments

@nebolsin
Copy link
Member

nebolsin commented Nov 2, 2020

stellar-core 15.0.0 introduces breaking changes to the DB schema: stellar/stellar-core#2593

For now I fixed it in a quick and dirty way by applying the following changes to the running stellar-core DB:

CREATE SCHEMA xdrs;
CREATE OR REPLACE FUNCTION xdrs.xdr_int64(xdr bytea, inout pos integer, out result bigint) AS $$
  SELECT pos + 8, ('x' || encode(substring(xdr from pos for 8), 'hex'))::bit(64)::bigint
$$ LANGUAGE SQL IMMUTABLE STRICT;

CREATE OR REPLACE FUNCTION buyingLiabilities(acc accounts) RETURNS bigint AS $$
    SELECT coalesce(buying.value, 0)
    FROM decode(acc.extension, 'base64') accraw(xdrbytes),
         xdrs.xdr_int64(accraw.xdrbytes, 5) as buying(pos, value)
$$ LANGUAGE SQL IMMUTABLE STRICT;

CREATE OR REPLACE FUNCTION sellingLiabilities(acc accounts) RETURNS bigint AS $$
    SELECT coalesce(selling.value, 0)
    FROM decode(acc.extension, 'base64') accraw(xdrbytes),
         xdrs.xdr_int64(accraw.xdrbytes, 13) as selling(pos, value)
$$ LANGUAGE SQL IMMUTABLE STRICT;

CREATE OR REPLACE FUNCTION buyingLiabilities(tl trustlines) RETURNS bigint AS $$
    SELECT coalesce(buying.value, 0)
    FROM decode(tl.extension, 'base64') accraw(xdrbytes),
         xdrs.xdr_int64(accraw.xdrbytes, 5) as buying(pos, value)
$$ LANGUAGE SQL IMMUTABLE STRICT;

CREATE OR REPLACE FUNCTION sellingLiabilities(tl trustlines) RETURNS bigint AS $$
    SELECT coalesce(selling.value, 0)
    FROM decode(tl.extension, 'base64') accraw(xdrbytes),
         xdrs.xdr_int64(accraw.xdrbytes, 13) as selling(pos, value)
$$ LANGUAGE SQL IMMUTABLE STRICT;

It seems to solve an issue for the time being, but we need to update Astrograph ORM layer to work with the new LedgerEntry format which stores extensions as base64-encoded XDR: entry-specific extension (AccountEntryExt, TrustLineEntryExt) in extension column, and common extension (LedgerEntryExt) in ledgerext column. It's similar to how we currently work with account signers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants