Skip to content

Commit bd106db

Browse files
authored
services/horizon: Insert signers's sponsorship information during state ingestion (#3096)
Fixes `SignersProcessor` to insert sponsorship information during state ingestion from history archives. `SignersProcessor` operates in two modes: `useLedgerEntryCache` set to `true` or `false`. When ingesting history archives we use `useLedgerEntryCache=false` to save memory - ledger entry cache is not needed because there are only inserts. This code path was not updated to include information about the sponsor of a signer.
1 parent 54d4127 commit bd106db

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Diff for: services/horizon/internal/expingest/processors/signer_processor_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package processors
44
import (
55
"testing"
66

7+
"github.com/guregu/null"
78
ingesterrors "github.com/stellar/go/exp/ingest/errors"
89
"github.com/stellar/go/exp/ingest/io"
910
"github.com/stellar/go/services/horizon/internal/db2/history"
@@ -98,6 +99,53 @@ func (s *AccountsSignerProcessorTestSuiteState) TestCreatesSigners() {
9899

99100
}
100101

102+
func (s *AccountsSignerProcessorTestSuiteState) TestCreatesSignerWithSponsor() {
103+
s.mockBatchInsertBuilder.
104+
On("Add", history.AccountSigner{
105+
Account: "GCCCU34WDY2RATQTOOQKY6SZWU6J5DONY42SWGW2CIXGW4LICAGNRZKX",
106+
Signer: "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML",
107+
Weight: int32(10),
108+
Sponsor: null.StringFrom("GDWZ6MKJP5ESVIB7O5RW4UFFGSCDILPEKDXWGG4HXXSHEZZPTKLR6UVG"),
109+
}).Return(nil).Once()
110+
111+
sponsorshipDescriptor := xdr.MustAddress("GDWZ6MKJP5ESVIB7O5RW4UFFGSCDILPEKDXWGG4HXXSHEZZPTKLR6UVG")
112+
113+
err := s.processor.ProcessChange(io.Change{
114+
Type: xdr.LedgerEntryTypeAccount,
115+
Pre: nil,
116+
Post: &xdr.LedgerEntry{
117+
Data: xdr.LedgerEntryData{
118+
Type: xdr.LedgerEntryTypeAccount,
119+
Account: &xdr.AccountEntry{
120+
AccountId: xdr.MustAddress("GCCCU34WDY2RATQTOOQKY6SZWU6J5DONY42SWGW2CIXGW4LICAGNRZKX"),
121+
Signers: []xdr.Signer{
122+
{
123+
Key: xdr.MustSigner("GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML"),
124+
Weight: 10,
125+
},
126+
},
127+
Ext: xdr.AccountEntryExt{
128+
V: 1,
129+
V1: &xdr.AccountEntryExtensionV1{
130+
Ext: xdr.AccountEntryExtensionV1Ext{
131+
V: 2,
132+
V2: &xdr.AccountEntryExtensionV2{
133+
NumSponsored: 1,
134+
NumSponsoring: 0,
135+
SignerSponsoringIDs: []xdr.SponsorshipDescriptor{
136+
&sponsorshipDescriptor,
137+
},
138+
},
139+
},
140+
},
141+
},
142+
},
143+
},
144+
},
145+
})
146+
s.Assert().NoError(err)
147+
}
148+
101149
func TestAccountsSignerProcessorTestSuiteLedger(t *testing.T) {
102150
suite.Run(t, new(AccountsSignerProcessorTestSuiteLedger))
103151
}

Diff for: services/horizon/internal/expingest/processors/signers_processor.go

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package processors
22

33
import (
4+
"github.com/guregu/null"
45
ingesterrors "github.com/stellar/go/exp/ingest/errors"
56
"github.com/stellar/go/exp/ingest/io"
67
"github.com/stellar/go/services/horizon/internal/db2/history"
@@ -61,11 +62,18 @@ func (p *SignersProcessor) ProcessChange(change io.Change) error {
6162
accountEntry := change.Post.Data.MustAccount()
6263
account := accountEntry.AccountId.Address()
6364

65+
sponsors := accountEntry.SponsorPerSigner()
6466
for signer, weight := range accountEntry.SignerSummary() {
67+
var sponsor null.String
68+
if sponsorDesc, isSponsored := sponsors[signer]; isSponsored {
69+
sponsor = null.StringFrom(sponsorDesc.Address())
70+
}
71+
6572
err := p.batch.Add(history.AccountSigner{
6673
Account: account,
6774
Signer: signer,
6875
Weight: weight,
76+
Sponsor: sponsor,
6977
})
7078
if err != nil {
7179
return errors.Wrap(err, "Error adding row to accountSignerBatch")

0 commit comments

Comments
 (0)