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

Cleanup ticket buyer v2 #2412

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 18 additions & 18 deletions internal/rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ type accountMixerServer struct {

// ticketbuyerServer provides RPC clients with the ability to start/stop the
// automatic ticket buyer service.
type ticketbuyerV2Server struct {
type ticketbuyerServer struct {
ready atomic.Uint32
loader *loader.Loader
pb.UnimplementedTicketBuyerV2ServiceServer
pb.UnimplementedTicketBuyerServiceServer
}

type agendaServer struct {
Expand Down Expand Up @@ -255,7 +255,7 @@ var (
loaderService loaderServer
seedService seedServer
accountMixerService accountMixerServer
ticketBuyerV2Service ticketbuyerV2Server
ticketBuyerService ticketbuyerServer
agendaService agendaServer
votingService votingServer
messageVerificationService messageVerificationServer
Expand All @@ -271,7 +271,7 @@ func RegisterServices(server *grpc.Server) {
pb.RegisterWalletLoaderServiceServer(server, &loaderService)
pb.RegisterSeedServiceServer(server, &seedService)
pb.RegisterAccountMixerServiceServer(server, &accountMixerService)
pb.RegisterTicketBuyerV2ServiceServer(server, &ticketBuyerV2Service)
pb.RegisterTicketBuyerServiceServer(server, &ticketBuyerService)
pb.RegisterAgendaServiceServer(server, &agendaService)
pb.RegisterVotingServiceServer(server, &votingService)
pb.RegisterMessageVerificationServiceServer(server, &messageVerificationService)
Expand All @@ -285,7 +285,7 @@ var serviceMap = map[string]any{
"walletrpc.WalletLoaderService": &loaderService,
"walletrpc.SeedService": &seedService,
"walletrpc.AccountMixerService": &accountMixerService,
"walletrpc.TicketBuyerV2Service": &ticketBuyerV2Service,
"walletrpc.TicketBuyerService": &ticketBuyerService,
"walletrpc.AgendaService": &agendaService,
"walletrpc.VotingService": &votingService,
"walletrpc.MessageVerificationService": &messageVerificationService,
Expand Down Expand Up @@ -2573,7 +2573,7 @@ func (t *accountMixerServer) RunAccountMixer(req *pb.RunAccountMixerRequest, svr

tb := ticketbuyer.New(wallet)

// Set ticketbuyerV2 config
// Set ticketbuyer config
tb.AccessConfig(func(c *ticketbuyer.Config) {
c.Mixing = req.CsppServer != ""
c.MixedAccountBranch = req.MixedAccountBranch
Expand Down Expand Up @@ -2613,16 +2613,16 @@ func (t *accountMixerServer) checkReady() bool {
return t.ready.Load() != 0
}

// StartTicketBuyerV2Service starts the TicketBuyerV2Service.
func StartTicketBuyerV2Service(server *grpc.Server, loader *loader.Loader) {
ticketBuyerV2Service.loader = loader
if ticketBuyerV2Service.ready.Swap(1) != 0 {
// StartTicketBuyerService starts the TicketBuyerService.
func StartTicketBuyerService(server *grpc.Server, loader *loader.Loader) {
ticketBuyerService.loader = loader
if ticketBuyerService.ready.Swap(1) != 0 {
panic("service already started")
}
}

// StartTicketBuyer starts the automatic ticket buyer for the v2 service.
func (t *ticketbuyerV2Server) RunTicketBuyer(req *pb.RunTicketBuyerRequest, svr pb.TicketBuyerV2Service_RunTicketBuyerServer) error {
// RunTicketBuyer starts the automatic ticket buyer.
func (t *ticketbuyerServer) RunTicketBuyer(req *pb.RunTicketBuyerRequest, svr pb.TicketBuyerService_RunTicketBuyerServer) error {
wallet, ok := t.loader.LoadedWallet()
if !ok {
return status.Errorf(codes.FailedPrecondition, "Wallet has not been loaded")
Expand Down Expand Up @@ -2668,7 +2668,7 @@ func (t *ticketbuyerV2Server) RunTicketBuyer(req *pb.RunTicketBuyerRequest, svr
}
vspClient, err = loader.VSP(cfg)
if err != nil {
return status.Errorf(codes.Unknown, "TicketBuyerV3 instance failed to start. Error: %v", err)
return status.Errorf(codes.Unknown, "TicketBuyer instance failed to start. Error: %v", err)
}
}
if req.BalanceToMaintain < 0 {
Expand Down Expand Up @@ -2714,7 +2714,7 @@ func (t *ticketbuyerV2Server) RunTicketBuyer(req *pb.RunTicketBuyerRequest, svr
limit := int(req.Limit)

tb := ticketbuyer.New(wallet)
// Set ticketbuyerV2 config
// Set ticketbuyer config
tb.AccessConfig(func(c *ticketbuyer.Config) {
c.BuyTickets = true
c.Account = req.Account
Expand Down Expand Up @@ -2749,15 +2749,15 @@ func (t *ticketbuyerV2Server) RunTicketBuyer(req *pb.RunTicketBuyerRequest, svr
err = tb.Run(svr.Context(), req.Passphrase)
if err != nil {
if svr.Context().Err() != nil {
return status.Errorf(codes.Canceled, "TicketBuyerV2 instance canceled, account number: %v", req.Account)
return status.Errorf(codes.Canceled, "TicketBuyer instance canceled, account number: %v", req.Account)
}
return status.Errorf(codes.Unknown, "TicketBuyerV2 instance errored: %v", err)
return status.Errorf(codes.Unknown, "TicketBuyer instance errored: %v", err)
}

return nil
}

func (t *ticketbuyerV2Server) checkReady() bool {
func (t *ticketbuyerServer) checkReady() bool {
return t.ready.Load() != 0
}

Expand Down Expand Up @@ -4157,7 +4157,7 @@ func (s *walletServer) SyncVSPFailedTickets(ctx context.Context, req *pb.SyncVSP
}
vspClient, err := loader.VSP(cfg)
if err != nil {
return nil, status.Errorf(codes.Unknown, "TicketBuyerV3 instance failed to start. Error: %v", err)
return nil, status.Errorf(codes.Unknown, "TicketBuyer instance failed to start. Error: %v", err)
}

// Process tickets fee if needed.
Expand Down
104 changes: 1 addition & 103 deletions rpc/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,8 @@ service WalletLoaderService {
service AccountMixerService {
rpc RunAccountMixer (RunAccountMixerRequest) returns (stream RunAccountMixerResponse);
}
service TicketBuyerV2Service {
rpc RunTicketBuyer (RunTicketBuyerRequest) returns (stream RunTicketBuyerResponse);
}

service TicketBuyerService {
rpc StartAutoBuyer (StartAutoBuyerRequest) returns (StartAutoBuyerResponse);
rpc StopAutoBuyer (StopAutoBuyerRequest) returns (StopAutoBuyerResponse);
rpc TicketBuyerConfig (TicketBuyerConfigRequest) returns (TicketBuyerConfigResponse);
rpc SetAccount (SetAccountRequest) returns (SetAccountResponse);
rpc SetBalanceToMaintain (SetBalanceToMaintainRequest) returns (SetBalanceToMaintainResponse);
rpc SetMaxFee (SetMaxFeeRequest) returns (SetMaxFeeResponse);
rpc SetMaxPriceRelative (SetMaxPriceRelativeRequest) returns (SetMaxPriceRelativeResponse);
rpc SetMaxPriceAbsolute (SetMaxPriceAbsoluteRequest) returns (SetMaxPriceAbsoluteResponse);
rpc SetVotingAddress (SetVotingAddressRequest) returns (SetVotingAddressResponse);
rpc SetPoolAddress (SetPoolAddressRequest) returns (SetPoolAddressResponse);
rpc SetPoolFees (SetPoolFeesRequest) returns (SetPoolFeesResponse);
rpc SetMaxPerBlock (SetMaxPerBlockRequest) returns (SetMaxPerBlockResponse);
rpc RunTicketBuyer (RunTicketBuyerRequest) returns (stream RunTicketBuyerResponse);
}

service SeedService {
Expand Down Expand Up @@ -933,93 +918,6 @@ message RunAccountMixerRequest {

message RunAccountMixerResponse {}

message StartAutoBuyerRequest {
bytes passphrase = 1;
uint32 account = 2;
int64 balance_to_maintain = 3;
int64 max_fee_per_kb = 4;
double max_price_relative = 5;
int64 max_price_absolute = 6;
string voting_address = 7;
string pool_address = 8;
double pool_fees = 9;
int64 max_per_block = 10;
}
message StartAutoBuyerResponse {}

message StopAutoBuyerRequest {}
message StopAutoBuyerResponse {}
message TicketBuyerConfigRequest{
}

message TicketBuyerConfigResponse{
uint32 account = 1;
string avg_price_mode = 2;
int64 avg_priceVWAP_delta = 3;
int64 balance_to_maintain = 4;
int64 blocks_to_avg = 5;
bool dont_wait_for_tickets = 6;
int64 expiry_delta = 7;
string fee_source = 8;
double fee_target_scaling = 9;
int64 min_fee = 10;
int64 max_fee = 12;
int64 max_per_block = 13;
int64 max_price_absolute = 14;
double max_price_relative = 15;
int64 max_in_mempool = 17;
string pool_address = 18;
double pool_fees = 19;
bool spread_ticket_purchases = 20;
string voting_address = 21;
int64 tx_fee = 22;
}

message SetAccountRequest{
uint32 account = 1;
}
message SetAccountResponse{}

message SetBalanceToMaintainRequest{
int64 balance_to_maintain = 1;
}
message SetBalanceToMaintainResponse{}

message SetMaxFeeRequest{
int64 max_fee_per_kb = 1;
}
message SetMaxFeeResponse{}

message SetMaxPriceRelativeRequest{
double max_price_relative = 1;
}
message SetMaxPriceRelativeResponse{}

message SetMaxPriceAbsoluteRequest{
int64 max_price_absolute = 1;
}
message SetMaxPriceAbsoluteResponse{}

message SetVotingAddressRequest{
string voting_address = 1;
}
message SetVotingAddressResponse{}

message SetPoolAddressRequest{
string pool_address = 1;
}
message SetPoolAddressResponse{}

message SetPoolFeesRequest{
double pool_fees = 1;
}
message SetPoolFeesResponse{}

message SetMaxPerBlockRequest{
int64 max_per_block = 1;
}
message SetMaxPerBlockResponse{}

message AgendasRequest {}
message AgendasResponse {
message Agenda {
Expand Down
Loading
Loading