Skip to content

Commit fe9b5ec

Browse files
committed
Merge branch 'master' into protocol-23
2 parents 9ad4cdc + c453f8b commit fe9b5ec

File tree

90 files changed

+5108
-1612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5108
-1612
lines changed

.github/actions/setup-go/action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ runs:
3232
run: echo 'PREFIX=${{ github.workflow }}-${{ github.job }}-${{ runner.os }}-${{ inputs.go-version }}-matrix(${{ join(matrix.*,'|') }})' >> $GITHUB_ENV
3333

3434
# Cache the Go Modules downloaded during the job.
35-
- uses: actions/cache@v2
35+
- uses: actions/cache@v4
3636
with:
3737
path: ~/go/pkg/mod
3838
key: ${{ env.PREFIX }}-go-mod-${{ hashFiles('**/go.sum') }}
3939
restore-keys: ${{ env.PREFIX }}-go-mod-
4040

4141
# Cache any build and test artifacts during the job, which will speed up
4242
# rebuilds and cause test runs to skip tests that have no reason to rerun.
43-
- uses: actions/cache@v2
43+
- uses: actions/cache@v4
4444
with:
4545
path: ~/.cache/go-build
4646
key: ${{ env.PREFIX }}-go-build-${{ github.ref }}-${{ hashFiles('**', '!.git') }}

.github/workflows/horizon.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
104104
- name: Restore Horizon binary and integration tests source hash to cache
105105
id: horizon_binary_tests_hash
106-
uses: actions/cache/restore@v3
106+
uses: actions/cache/restore@v4
107107
with:
108108
path: ./empty
109109
lookup-only: true
@@ -114,7 +114,7 @@ jobs:
114114

115115
- name: Save Horizon binary and integration tests source hash to cache
116116
if: ${{ success() && steps.horizon_binary_tests_hash.outputs.cache-hit != 'true' }}
117-
uses: actions/cache/save@v3
117+
uses: actions/cache/save@v4
118118
with:
119119
path: ./empty
120120
key: ${{ env.COMBINED_SOURCE_HASH }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ debug
2121
*.db
2222
*.conf
2323
*.lock
24+
.proto_checksums

Makefile

+45
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,48 @@ xdr-clean:
7373
rm $(DOWNLOADABLE_XDRS) || true
7474

7575
xdr-update: xdr-clean xdr
76+
77+
78+
##############
79+
PROTO_DIR := protos
80+
GEN_SUFFIX := .pb.go
81+
PROTO_FILES := $(shell find $(PROTO_DIR) -name "*.proto")
82+
PROTO_CHECKSUM := .proto_checksums
83+
84+
generate-proto:
85+
@echo "Regenerating proto files..."
86+
@touch $(PROTO_CHECKSUM)
87+
@current_checksum=$$(sha256sum $(PROTO_FILES) | sha256sum | awk '{print $$1}'); \
88+
stored_checksum=$$(cat $(PROTO_CHECKSUM)); \
89+
if [ "$${current_checksum}" != "$${stored_checksum}" ]; then \
90+
echo "Changes detected. Regenerating all proto files..."; \
91+
MAP_OPTS=$$(for file in $(PROTO_FILES); do \
92+
rel_path=$$(echo $$file | sed 's|$(PROTO_DIR)/||'); \
93+
pkg_path=$$(dirname $$rel_path); \
94+
go_pkg="github.com/stellar/go/$$pkg_path"; \
95+
printf "M%s=%s," "$$rel_path" "$$go_pkg"; \
96+
done); \
97+
MAP_OPTS=$${MAP_OPTS%,}; \
98+
echo "Running protoc with options:"; \
99+
echo " --go_out=."; \
100+
echo " --go_opt=paths=source_relative"; \
101+
echo " --go_opt=$$MAP_OPTS"; \
102+
echo "Proto Files: $(PROTO_FILES)"; \
103+
protoc -I=$(PROTO_DIR) \
104+
--go_out=. --go_opt=paths=source_relative \
105+
--go_opt=$$MAP_OPTS \
106+
$(PROTO_FILES); \
107+
echo "$${current_checksum}" > $(PROTO_CHECKSUM); \
108+
else \
109+
echo "No changes detected in proto files."; \
110+
fi
111+
112+
113+
regenerate-proto: $(PROTO_CHECKSUM)
114+
rm -f $(PROTO_CHECKSUM)
115+
$(MAKE) generate-proto
116+
117+
$(PROTO_CHECKSUM):
118+
@touch $(PROTO_CHECKSUM)
119+
120+
.PHONY: generate-proto regenerate-proto

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ In addition to the other top-level packages, there are a few special directories
4545
* **support/scripts** contains single-file go programs and bash scripts used to support the development of this repo.
4646
* **services** contains packages that compile to applications that are long-running processes (such as API servers).
4747
* **tools** contains packages that compile to command line applications.
48+
* **protos** contains the protobuf definitions for data-models that we want to generate for use with external stakeholders. Refer to [protos/README.md](./protos/README.md) for more information about code structure in `protos` directory
4849

4950
Each of these directories have their own README file that explain further the nature of their contents.
5051

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ require (
178178
google.golang.org/appengine v1.6.8 // indirect
179179
google.golang.org/genproto v0.0.0-20240528184218-531527333157 // indirect
180180
google.golang.org/grpc v1.64.1 // indirect
181-
google.golang.org/protobuf v1.34.2 // indirect
181+
google.golang.org/protobuf v1.34.2
182182
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
183183
gopkg.in/yaml.v3 v3.0.1 // indirect
184184
)

historyarchive/archive.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ type ArchiveInterface interface {
7979
ListAllBuckets() (chan string, chan error)
8080
ListAllBucketHashes() (chan Hash, chan error)
8181
ListCategoryCheckpoints(cat string, pth string) (chan uint32, chan error)
82-
GetXdrStreamForHash(hash Hash) (*XdrStream, error)
83-
GetXdrStream(pth string) (*XdrStream, error)
82+
GetXdrStreamForHash(hash Hash) (*xdr.Stream, error)
83+
GetXdrStream(pth string) (*xdr.Stream, error)
8484
GetCheckpointManager() CheckpointManager
8585
GetStats() []ArchiveStats
8686
}
@@ -391,19 +391,19 @@ func (a *Archive) GetBucketPathForHash(hash Hash) string {
391391
)
392392
}
393393

394-
func (a *Archive) GetXdrStreamForHash(hash Hash) (*XdrStream, error) {
394+
func (a *Archive) GetXdrStreamForHash(hash Hash) (*xdr.Stream, error) {
395395
return a.GetXdrStream(a.GetBucketPathForHash(hash))
396396
}
397397

398-
func (a *Archive) GetXdrStream(pth string) (*XdrStream, error) {
398+
func (a *Archive) GetXdrStream(pth string) (*xdr.Stream, error) {
399399
if !strings.HasSuffix(pth, ".xdr.gz") {
400400
return nil, errors.New("File has non-.xdr.gz suffix: " + pth)
401401
}
402402
rdr, err := a.cachedGet(pth)
403403
if err != nil {
404404
return nil, err
405405
}
406-
return NewXdrGzStream(rdr)
406+
return xdr.NewGzStream(rdr)
407407
}
408408

409409
func (a *Archive) cachedGet(pth string) (io.ReadCloser, error) {

historyarchive/archive_pool.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,17 @@ func (pa *ArchivePool) PutRootHAS(has HistoryArchiveState, opts *CommandOptions)
226226
})
227227
}
228228

229-
func (pa *ArchivePool) GetXdrStreamForHash(hash Hash) (*XdrStream, error) {
230-
var stream *XdrStream
229+
func (pa *ArchivePool) GetXdrStreamForHash(hash Hash) (*xdr.Stream, error) {
230+
var stream *xdr.Stream
231231
return stream, pa.runRoundRobin(func(ai ArchiveInterface) error {
232232
var err error
233233
stream, err = ai.GetXdrStreamForHash(hash)
234234
return err
235235
})
236236
}
237237

238-
func (pa *ArchivePool) GetXdrStream(pth string) (*XdrStream, error) {
239-
var stream *XdrStream
238+
func (pa *ArchivePool) GetXdrStream(pth string) (*xdr.Stream, error) {
239+
var stream *xdr.Stream
240240
return stream, pa.runRoundRobin(func(ai ArchiveInterface) error {
241241
var err error
242242
stream, err = ai.GetXdrStream(pth)

historyarchive/hash.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"crypto/sha256"
99
"encoding/hex"
1010
"fmt"
11+
12+
"github.com/stellar/go/xdr"
1113
)
1214

13-
type Hash [sha256.Size]byte
15+
type Hash xdr.Hash
1416

1517
func DecodeHash(s string) (Hash, error) {
1618
var h Hash

historyarchive/json.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func DumpXdrAsJson(args []string) error {
3535
}
3636

3737
base := path.Base(arg)
38-
xr := NewXdrStream(rdr)
38+
xr := xdr.NewStream(rdr)
3939
n := 0
4040
for {
4141
var lhe xdr.LedgerHeaderHistoryEntry

historyarchive/mocks.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package historyarchive
22

33
import (
4-
"github.com/stellar/go/xdr"
54
"github.com/stretchr/testify/mock"
5+
6+
"github.com/stellar/go/xdr"
67
)
78

89
// MockArchive is a mockable archive.
@@ -99,14 +100,14 @@ func (m *MockArchive) ListCategoryCheckpoints(cat string, pth string) (chan uint
99100
return make(chan uint32), make(chan error)
100101
}
101102

102-
func (m *MockArchive) GetXdrStreamForHash(hash Hash) (*XdrStream, error) {
103+
func (m *MockArchive) GetXdrStreamForHash(hash Hash) (*xdr.Stream, error) {
103104
a := m.Called(hash)
104-
return a.Get(0).(*XdrStream), a.Error(1)
105+
return a.Get(0).(*xdr.Stream), a.Error(1)
105106
}
106107

107-
func (m *MockArchive) GetXdrStream(pth string) (*XdrStream, error) {
108+
func (m *MockArchive) GetXdrStream(pth string) (*xdr.Stream, error) {
108109
a := m.Called(pth)
109-
return a.Get(0).(*XdrStream), a.Error(1)
110+
return a.Get(0).(*xdr.Stream), a.Error(1)
110111
}
111112

112113
func (m *MockArchive) GetStats() []ArchiveStats {

historyarchive/verify.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ func SortTxsForHash(txset *xdr.TransactionSet) error {
5151
hsh: make([]Hash, len(txset.Txs)),
5252
}
5353
for i, tx := range txset.Txs {
54-
h, err := HashXdr(&tx)
54+
h, err := xdr.HashXdr(&tx)
5555
if err != nil {
5656
return err
5757
}
58-
bh.hsh[i] = h
58+
bh.hsh[i] = Hash(h)
5959
}
6060
sort.Sort(bh)
6161
return nil
@@ -86,18 +86,18 @@ func HashEmptyTxSet(previousLedgerHash Hash) Hash {
8686
}
8787

8888
func (arch *Archive) VerifyLedgerHeaderHistoryEntry(entry *xdr.LedgerHeaderHistoryEntry) error {
89-
h, err := HashXdr(&entry.Header)
89+
h, err := xdr.HashXdr(&entry.Header)
9090
if err != nil {
9191
return err
9292
}
93-
if h != Hash(entry.Hash) {
93+
if h != entry.Hash {
9494
return fmt.Errorf("Ledger %d expected hash %s, got %s",
9595
entry.Header.LedgerSeq, Hash(entry.Hash), Hash(h))
9696
}
9797
arch.mutex.Lock()
9898
defer arch.mutex.Unlock()
9999
seq := uint32(entry.Header.LedgerSeq)
100-
arch.actualLedgerHashes[seq] = h
100+
arch.actualLedgerHashes[seq] = Hash(h)
101101
arch.expectLedgerHashes[seq-1] = Hash(entry.Header.PreviousLedgerHash)
102102
arch.expectTxSetHashes[seq] = Hash(entry.Header.ScpValue.TxSetHash)
103103
arch.expectTxResultSetHashes[seq] = Hash(entry.Header.TxSetResultHash)
@@ -117,13 +117,13 @@ func (arch *Archive) VerifyTransactionHistoryEntry(entry *xdr.TransactionHistory
117117
}
118118

119119
func (arch *Archive) VerifyTransactionHistoryResultEntry(entry *xdr.TransactionHistoryResultEntry) error {
120-
h, err := HashXdr(&entry.TxResultSet)
120+
h, err := xdr.HashXdr(&entry.TxResultSet)
121121
if err != nil {
122122
return err
123123
}
124124
arch.mutex.Lock()
125125
defer arch.mutex.Unlock()
126-
arch.actualTxResultSetHashes[uint32(entry.LedgerSeq)] = h
126+
arch.actualTxResultSetHashes[uint32(entry.LedgerSeq)] = Hash(h)
127127
return nil
128128
}
129129

0 commit comments

Comments
 (0)