Skip to content

Commit 4058f7d

Browse files
authored
feat: startup configuration (#18)
* Allow coordinator to be set manually * Add manual coordinator test * Implement across message handler * Send signature to all relayers * Implement signature cache to store generated signatures * Speed up process coordination * Implement signature cache to store generated signatures * Add signature cache tests * Allow for coordinator to notify other relayers of an across message * Reduce tss timeout * Implement calculation of the unlock hash that matches on-chain implementation * Add across message handler tests * Update mocks to maintained version * Fix test race condition * Convert abi to constant * Use source chain id property from across data * Use message destination as across deposit source * Use coordinator from the host in message handler * Send across message result over the err chanel * Return api errors as json * Implement api serve function * Add signing handler tests * Ignore valid json encode errors * Enforce protocol type on the signing API * Update signing url * Implement signature cache subscribe * Implement status sse endpoint * Bump action cache action * Set chain id as uint64 * Deprecate propstore * Add across pool address to config * Make signature cache watch a separate function * Add api addr to config * Implement startup configuration * Remove uploader config * Bump golang version * Add example config * Fix app startup * Fix across message infinite loop * Fix across tests * Make test less flaky * Remove print * Remove unnecessary waits * Lint * Ignore irrelevant coordinator errors * Try to execute tss process in spite of not notifying everyone * Fix coordinator error assignemnt * Add manual timeout to keygen * Increase coordintor timeout in tests * Increase tss process timeout
1 parent 6f4ace1 commit 4058f7d

33 files changed

+486
-782
lines changed

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
FROM alpine:3.6 as alpine
55
RUN apk add -U --no-cache ca-certificates
66

7-
FROM golang:1.19 AS builder
7+
FROM golang:1.23 AS builder
88
ADD . /src
99
WORKDIR /src
1010
RUN cd /src && echo $(ls -1 /src)
1111
RUN go mod download
12-
RUN go build -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore -X github.com/sprintertech/sprinter-signing/app.Version=$(sed -n '0,/## \[\([0-9.]*\)\]/s/.*\[\([0-9.]*\)\].*/\1/p' CHANGELOG.md)" -o /bridge .
12+
RUN go build -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore -X github.com/sprintertech/sprinter-signing/app.Version=$(sed -n '0,/## \[\([0-9.]*\)\]/s/.*\[\([0-9.]*\)\].*/\1/p' CHANGELOG.md)" -o /signing .
1313

1414
# final stage
1515
FROM debian:stable-slim
16-
COPY --from=builder /bridge ./
17-
RUN chmod +x ./bridge
16+
COPY --from=builder /signing ./
17+
RUN chmod +x ./signing
1818
RUN mkdir -p /mount
1919
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2020

21-
ENTRYPOINT ["./bridge"]
21+
ENTRYPOINT ["./signing"]

api/handlers/signing_test.go

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,23 @@ import (
2424
type SigningHandlerTestSuite struct {
2525
suite.Suite
2626

27-
handler *handlers.SigningHandler
28-
msgChn chan []*message.Message
27+
chains map[uint64]struct{}
2928
}
3029

3130
func TestRunSigningHandlerTestSuite(t *testing.T) {
3231
suite.Run(t, new(SigningHandlerTestSuite))
3332
}
3433

3534
func (s *SigningHandlerTestSuite) SetupTest() {
36-
ctrl := gomock.NewController(s.T())
37-
defer ctrl.Finish()
38-
3935
chains := make(map[uint64]struct{})
4036
chains[1] = struct{}{}
41-
42-
s.msgChn = make(chan []*message.Message, 1)
43-
s.handler = handlers.NewSigningHandler(s.msgChn, chains)
37+
s.chains = chains
4438
}
4539

4640
func (s *SigningHandlerTestSuite) Test_HandleSigning_MissingDepositID() {
41+
msgChn := make(chan []*message.Message)
42+
handler := handlers.NewSigningHandler(msgChn, s.chains)
43+
4744
input := handlers.SigningBody{
4845
Protocol: "across",
4946
}
@@ -58,17 +55,20 @@ func (s *SigningHandlerTestSuite) Test_HandleSigning_MissingDepositID() {
5855
recorder := httptest.NewRecorder()
5956

6057
go func() {
61-
msg := <-s.msgChn
58+
msg := <-msgChn
6259
ad := msg[0].Data.(across.AcrossData)
6360
ad.ErrChn <- fmt.Errorf("error handling message")
6461
}()
6562

66-
s.handler.HandleSigning(recorder, req)
63+
handler.HandleSigning(recorder, req)
6764

6865
s.Equal(http.StatusBadRequest, recorder.Code)
6966
}
7067

7168
func (s *SigningHandlerTestSuite) Test_HandleSigning_InvalidChainID() {
69+
msgChn := make(chan []*message.Message)
70+
handler := handlers.NewSigningHandler(msgChn, s.chains)
71+
7272
input := handlers.SigningBody{
7373
DepositId: &handlers.BigInt{big.NewInt(1000)},
7474
Protocol: "across",
@@ -84,17 +84,20 @@ func (s *SigningHandlerTestSuite) Test_HandleSigning_InvalidChainID() {
8484
recorder := httptest.NewRecorder()
8585

8686
go func() {
87-
msg := <-s.msgChn
87+
msg := <-msgChn
8888
ad := msg[0].Data.(across.AcrossData)
8989
ad.ErrChn <- fmt.Errorf("error handling message")
9090
}()
9191

92-
s.handler.HandleSigning(recorder, req)
92+
handler.HandleSigning(recorder, req)
9393

9494
s.Equal(http.StatusBadRequest, recorder.Code)
9595
}
9696

9797
func (s *SigningHandlerTestSuite) Test_HandleSigning_ChainNotSupported() {
98+
msgChn := make(chan []*message.Message)
99+
handler := handlers.NewSigningHandler(msgChn, s.chains)
100+
98101
input := handlers.SigningBody{
99102
DepositId: &handlers.BigInt{big.NewInt(1000)},
100103
Protocol: "across",
@@ -110,17 +113,20 @@ func (s *SigningHandlerTestSuite) Test_HandleSigning_ChainNotSupported() {
110113
recorder := httptest.NewRecorder()
111114

112115
go func() {
113-
msg := <-s.msgChn
116+
msg := <-msgChn
114117
ad := msg[0].Data.(across.AcrossData)
115118
ad.ErrChn <- fmt.Errorf("error handling message")
116119
}()
117120

118-
s.handler.HandleSigning(recorder, req)
121+
handler.HandleSigning(recorder, req)
119122

120123
s.Equal(http.StatusBadRequest, recorder.Code)
121124
}
122125

123126
func (s *SigningHandlerTestSuite) Test_HandleSigning_InvalidProtocol() {
127+
msgChn := make(chan []*message.Message)
128+
handler := handlers.NewSigningHandler(msgChn, s.chains)
129+
124130
input := handlers.SigningBody{
125131
DepositId: &handlers.BigInt{big.NewInt(1000)},
126132
Protocol: "invalid",
@@ -136,17 +142,20 @@ func (s *SigningHandlerTestSuite) Test_HandleSigning_InvalidProtocol() {
136142
recorder := httptest.NewRecorder()
137143

138144
go func() {
139-
msg := <-s.msgChn
145+
msg := <-msgChn
140146
ad := msg[0].Data.(across.AcrossData)
141147
ad.ErrChn <- fmt.Errorf("error handling message")
142148
}()
143149

144-
s.handler.HandleSigning(recorder, req)
150+
handler.HandleSigning(recorder, req)
145151

146152
s.Equal(http.StatusBadRequest, recorder.Code)
147153
}
148154

149155
func (s *SigningHandlerTestSuite) Test_HandleSigning_ErrorHandlingMessage() {
156+
msgChn := make(chan []*message.Message)
157+
handler := handlers.NewSigningHandler(msgChn, s.chains)
158+
150159
input := handlers.SigningBody{
151160
DepositId: &handlers.BigInt{big.NewInt(1000)},
152161
Protocol: "across",
@@ -162,17 +171,20 @@ func (s *SigningHandlerTestSuite) Test_HandleSigning_ErrorHandlingMessage() {
162171
recorder := httptest.NewRecorder()
163172

164173
go func() {
165-
msg := <-s.msgChn
174+
msg := <-msgChn
166175
ad := msg[0].Data.(across.AcrossData)
167176
ad.ErrChn <- fmt.Errorf("error handling message")
168177
}()
169178

170-
s.handler.HandleSigning(recorder, req)
179+
handler.HandleSigning(recorder, req)
171180

172181
s.Equal(http.StatusInternalServerError, recorder.Code)
173182
}
174183

175184
func (s *SigningHandlerTestSuite) Test_HandleSigning_Success() {
185+
msgChn := make(chan []*message.Message)
186+
handler := handlers.NewSigningHandler(msgChn, s.chains)
187+
176188
input := handlers.SigningBody{
177189
DepositId: &handlers.BigInt{big.NewInt(1000)},
178190
Protocol: "across",
@@ -188,12 +200,12 @@ func (s *SigningHandlerTestSuite) Test_HandleSigning_Success() {
188200
recorder := httptest.NewRecorder()
189201

190202
go func() {
191-
msg := <-s.msgChn
203+
msg := <-msgChn
192204
ad := msg[0].Data.(across.AcrossData)
193205
ad.ErrChn <- nil
194206
}()
195207

196-
s.handler.HandleSigning(recorder, req)
208+
handler.HandleSigning(recorder, req)
197209

198210
s.Equal(http.StatusAccepted, recorder.Code)
199211
}

api/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ func Serve(
1717
statusHandler *handlers.StatusHandler,
1818
) {
1919
r := mux.NewRouter()
20-
r.HandleFunc("POST /v1/chains/{chainId:[0-9]+}/signatures", signingHandler.HandleSigning)
21-
r.HandleFunc("GET /v1/chains/{chainId:[0-9]+}/signatures/{depositId}", statusHandler.HandleRequest)
22-
http.Handle("/", r)
20+
r.HandleFunc("/v1/chains/{chainId:[0-9]+}/signatures", signingHandler.HandleSigning).Methods("POST")
21+
r.HandleFunc("/v1/chains/{chainId:[0-9]+}/signatures/{depositId}", statusHandler.HandleRequest).Methods("GET")
2322

2423
server := &http.Server{
2524
Addr: addr,
25+
Handler: r,
2626
ReadTimeout: time.Second * 10,
2727
}
2828
go func() {

0 commit comments

Comments
 (0)