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

services/horizon: Use bigint over timestamp for the new accounts.sequence_time column. #4337

Merged
merged 5 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
6 changes: 3 additions & 3 deletions services/horizon/internal/actions/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
Balance: 20000,
SequenceNumber: 223456789,
SequenceLedger: 2345,
SequenceTime: time.Unix(1647265533, 0),
SequenceTime: 1647265533,
NumSubEntries: 10,
Flags: 1,
HomeDomain: "stellar.org",
Expand All @@ -51,7 +51,7 @@ var (
Balance: 50000,
SequenceNumber: 648736,
SequenceLedger: 3456,
SequenceTime: time.Unix(1647365533, 0),
SequenceTime: 1647365533,
NumSubEntries: 10,
Flags: 2,
HomeDomain: "meridian.stellar.org",
Expand All @@ -69,7 +69,7 @@ var (
Balance: 50000,
SequenceNumber: 648736,
SequenceLedger: 4567,
SequenceTime: time.Unix(1647465533, 0),
SequenceTime: 1647465533,
NumSubEntries: 10,
Flags: 2,
MasterWeight: 5,
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/db2/history/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (q *Q) UpsertAccounts(ctx context.Context, accounts []AccountEntry) error {
{"selling_liabilities", "bigint", sellingLiabilities},
{"sequence_number", "bigint", sequenceNumber},
{"sequence_ledger", "int", sequenceLedger},
{"sequence_time", "timestamp", sequenceTime},
{"sequence_time", "bigint", sequenceTime},
{"num_subentries", "int", numSubEntries},
{"inflation_destination", "text", inflationDestination},
{"flags", "int", flags},
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/db2/history/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ type AccountEntry struct {
SellingLiabilities int64 `db:"selling_liabilities"`
SequenceNumber int64 `db:"sequence_number"`
SequenceLedger uint32 `db:"sequence_ledger"`
SequenceTime time.Time `db:"sequence_time"`
SequenceTime uint64 `db:"sequence_time"`
NumSubEntries uint32 `db:"num_subentries"`
InflationDestination string `db:"inflation_destination"`
HomeDomain string `db:"home_domain"`
Expand Down
68 changes: 11 additions & 57 deletions services/horizon/internal/db2/schema/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@ ALTER TABLE history_transactions ADD min_account_sequence_age bigint;
ALTER TABLE history_transactions ADD min_account_sequence_ledger_gap bigint;
ALTER TABLE history_transactions ADD extra_signers text[];

ALTER TABLE accounts ADD sequence_ledger integer;
ALTER TABLE accounts ADD sequence_time bigint;

-- CAP-40 signed payload strkeys can be 165 characters long, see
-- strkey/main.go:maxEncodedSize. But we'll use text here, so we don't need to
-- adjust it *ever again*.
ALTER TABLE accounts_signers
ALTER COLUMN signer TYPE text;

-- +migrate Down
ALTER TABLE history_transactions DROP ledger_bounds;
ALTER TABLE history_transactions DROP min_account_sequence;
ALTER TABLE history_transactions DROP min_account_sequence_age;
ALTER TABLE history_transactions DROP min_account_sequence_ledger_gap;
ALTER TABLE history_transactions DROP extra_signers;

ALTER TABLE accounts DROP sequence_ledger;
ALTER TABLE accounts DROP sequence_time;

ALTER TABLE accounts_signers
ALTER COLUMN signer TYPE character varying(64);

This file was deleted.

5 changes: 2 additions & 3 deletions services/horizon/internal/ingest/processor_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"reflect"
"testing"
"time"

"github.com/guregu/null"
"github.com/stretchr/testify/assert"
Expand All @@ -31,7 +30,7 @@ func TestProcessorRunnerRunHistoryArchiveIngestionGenesis(t *testing.T) {
AccountID: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7",
Balance: int64(1000000000000000000),
SequenceNumber: 0,
SequenceTime: time.Unix(0, 0).UTC(),
SequenceTime: 0,
MasterWeight: 1,
},
}).Return(nil).Once()
Expand Down Expand Up @@ -97,7 +96,7 @@ func TestProcessorRunnerRunHistoryArchiveIngestionHistoryArchive(t *testing.T) {
AccountID: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7",
Balance: int64(1000000000000000000),
SequenceNumber: 0,
SequenceTime: time.Unix(0, 0).UTC(),
SequenceTime: 0,
MasterWeight: 1,
},
}).Return(nil).Once()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package processors

import (
"context"

"github.com/stellar/go/ingest"
"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
"time"
)

type AccountsProcessor struct {
Expand Down Expand Up @@ -111,17 +111,14 @@ func (p *AccountsProcessor) ledgerEntryToRow(entry xdr.LedgerEntry) history.Acco
inflationDestination = account.InflationDest.Address()
}

seqTime := account.SeqTime()
seqLedger := account.SeqLedger()

return history.AccountEntry{
AccountID: account.AccountId.Address(),
Balance: int64(account.Balance),
BuyingLiabilities: int64(liabilities.Buying),
SellingLiabilities: int64(liabilities.Selling),
SequenceNumber: int64(account.SeqNum),
SequenceLedger: uint32(seqLedger),
SequenceTime: time.Unix(int64(seqTime), 0).UTC(),
SequenceLedger: uint32(account.SeqLedger()),
SequenceTime: uint64(account.SeqTime()),
NumSubEntries: uint32(account.NumSubEntries),
InflationDestination: inflationDestination,
Flags: uint32(account.Flags),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package processors
import (
"context"
"testing"
"time"

"github.com/stellar/go/ingest"
"github.com/stellar/go/services/horizon/internal/db2/history"
Expand Down Expand Up @@ -48,7 +47,7 @@ func (s *AccountsProcessorTestSuiteState) TestCreatesAccounts() {
{
LastModifiedLedger: 123,
AccountID: "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML",
SequenceTime: time.Unix(0, 0).UTC(),
SequenceTime: 0,
MasterWeight: 1,
ThresholdLow: 1,
ThresholdMedium: 1,
Expand Down Expand Up @@ -153,7 +152,7 @@ func (s *AccountsProcessorTestSuiteLedger) TestNewAccount() {
[]history.AccountEntry{
{
AccountID: "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML",
SequenceTime: time.Unix(0, 0).UTC(),
SequenceTime: 0,
MasterWeight: 0,
ThresholdLow: 1,
ThresholdMedium: 2,
Expand Down Expand Up @@ -215,8 +214,8 @@ func (s *AccountsProcessorTestSuiteLedger) TestNewAccountWithExtension() {
Ext: xdr.AccountEntryExtensionV2Ext{
V: 3,
V3: &xdr.AccountEntryExtensionV3{
SeqLedger: 2345,
SeqTime: 1647265533,
SeqLedger: 2346,
SeqTime: 1647265534,
},
},
},
Expand Down Expand Up @@ -251,8 +250,8 @@ func (s *AccountsProcessorTestSuiteLedger) TestNewAccountWithExtension() {
[]history.AccountEntry{
{
AccountID: "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML",
SequenceLedger: 2345,
SequenceTime: time.Unix(1647265533, 0).UTC(),
SequenceLedger: 2346,
SequenceTime: 1647265534,
MasterWeight: 0,
ThresholdLow: 1,
ThresholdMedium: 2,
Expand Down Expand Up @@ -339,7 +338,8 @@ func (s *AccountsProcessorTestSuiteLedger) TestProcessUpgradeChange() {
{
LastModifiedLedger: uint32(lastModifiedLedgerSeq) + 1,
AccountID: "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML",
SequenceTime: time.Unix(0, 0).UTC(),
SequenceTime: 0,
SequenceLedger: 0,
MasterWeight: 0,
ThresholdLow: 1,
ThresholdMedium: 2,
Expand Down Expand Up @@ -405,7 +405,8 @@ func (s *AccountsProcessorTestSuiteLedger) TestFeeProcessedBeforeEverythingElse(
LastModifiedLedger: 0,
AccountID: "GAHK7EEG2WWHVKDNT4CEQFZGKF2LGDSW2IVM4S5DP42RBW3K6BTODB4A",
Balance: 300,
SequenceTime: time.Unix(0, 0).UTC(),
SequenceTime: 0,
SequenceLedger: 0,
},
},
).Return(nil).Once()
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/ingest/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func addAccountsToStateVerifier(ctx context.Context, verifier *verify.StateVerif
V: 3,
V3: &xdr.AccountEntryExtensionV3{
SeqLedger: xdr.Uint32(row.SequenceLedger),
SeqTime: xdr.TimePoint(row.SequenceTime.Unix()),
SeqTime: xdr.TimePoint(row.SequenceTime),
},
},
},
Expand Down
5 changes: 4 additions & 1 deletion services/horizon/internal/ingest/verify_range_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ func (s *VerifyRangeStateTestSuite) TestSuccessWithVerify() {
Ext: xdr.AccountEntryExtensionV2Ext{
V: 3,
V3: &xdr.AccountEntryExtensionV3{
SeqTime: xdr.TimePoint(18446744011573954816),
SeqTime: xdr.TimePoint(18446744011573954816),
SeqLedger: xdr.Uint32(12345678),
},
},
},
Expand Down Expand Up @@ -484,6 +485,8 @@ func (s *VerifyRangeStateTestSuite) TestSuccessWithVerify() {
AccountID: mockAccountID,
Balance: 600,
LastModifiedLedger: 62,
SequenceTime: 18446744011573954816,
SequenceLedger: 12345678,
MasterWeight: 1,
NumSponsored: 0,
NumSponsoring: 2,
Expand Down
1 change: 0 additions & 1 deletion services/horizon/internal/ingest/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func genAccount(tt *test.T, gen randxdr.Generator) xdr.LedgerEntryChange {
{randxdr.FieldEquals("created.data.account.ext.v1.ext.v2.numSponsoring"), randxdr.SetPositiveNum32},
{randxdr.FieldEquals("created.data.account.ext.v1.ext.v2.numSponsored"), randxdr.SetPositiveNum32},
{randxdr.FieldEquals("created.data.account.ext.v1.ext.v2.signerSponsoringIDs"), randxdr.SetVecLen(numSigners)},
{randxdr.FieldEquals("created.data.account.ext.v1.ext.v2.ext.v"), randxdr.SetU32(0)},
{randxdr.FieldEquals("created.data.account.ext.v1.ext.v2.ext.v3.seqLedger"), randxdr.SetPositiveNum32},
{randxdr.FieldEquals("created.data.account.ext.v1.ext.v2.ext.v3.seqTime"), randxdr.SetPositiveNum64},
},
Expand Down
Loading