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

Add flag to use AI ServiceRegistry contract address for Livepeer AI Subnet #3186

Merged
merged 4 commits into from
Oct 22, 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
1 change: 1 addition & 0 deletions cmd/livepeer/livepeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func parseLivepeerConfig() starter.LivepeerConfig {
cfg.HevcDecoding = flag.Bool("hevcDecoding", *cfg.HevcDecoding, "Enable or disable HEVC decoding")

// AI:
cfg.AIServiceRegistry = flag.Bool("aiServiceRegistry", *cfg.AIServiceRegistry, "Set to true to use an AI ServiceRegistry contract address")
cfg.AIWorker = flag.Bool("aiWorker", *cfg.AIWorker, "Set to true to run an AI worker")
cfg.AIModels = flag.String("aiModels", *cfg.AIModels, "Set models (pipeline:model_id) for AI worker to load upon initialization")
cfg.AIModelsDir = flag.String("aiModelsDir", *cfg.AIModelsDir, "Set directory where AI model weights are stored")
Expand Down
16 changes: 12 additions & 4 deletions cmd/livepeer/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
HttpIngest *bool
Orchestrator *bool
Transcoder *bool
AIServiceRegistry *bool
AIWorker *bool
Gateway *bool
Broadcaster *bool
Expand Down Expand Up @@ -199,6 +200,7 @@
defaultTestTranscoder := true

// AI:
defaultAIServiceRegistry := false

Check warning on line 203 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L203

Added line #L203 was not covered by tests
defaultAIWorker := false
defaultAIModels := ""
defaultAIModelsDir := ""
Expand Down Expand Up @@ -298,10 +300,11 @@
TestTranscoder: &defaultTestTranscoder,

// AI:
AIWorker: &defaultAIWorker,
AIModels: &defaultAIModels,
AIModelsDir: &defaultAIModelsDir,
AIRunnerImage: &defaultAIRunnerImage,
AIServiceRegistry: &defaultAIServiceRegistry,
AIWorker: &defaultAIWorker,
AIModels: &defaultAIModels,
AIModelsDir: &defaultAIModelsDir,
AIRunnerImage: &defaultAIRunnerImage,

Check warning on line 307 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L303-L307

Added lines #L303 - L307 were not covered by tests

// Onchain:
EthAcctAddr: &defaultEthAcctAddr,
Expand Down Expand Up @@ -706,6 +709,11 @@
CheckTxTimeout: time.Duration(int64(*cfg.TxTimeout) * int64(*cfg.MaxTxReplacements+1)),
}

if *cfg.AIServiceRegistry {
// For the time-being Livepeer AI Subnet uses its own ServiceRegistry, so we define it here
ethCfg.ServiceRegistryAddr = ethcommon.HexToAddress("0x04C0b249740175999E5BF5c9ac1dA92431EF34C5")
}

Check warning on line 715 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L712-L715

Added lines #L712 - L715 were not covered by tests

client, err := eth.NewClient(ethCfg)
if err != nil {
glog.Errorf("Failed to create Livepeer Ethereum client: %v", err)
Expand Down
33 changes: 12 additions & 21 deletions eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,22 @@
Signer types.Signer
ControllerAddr ethcommon.Address
CheckTxTimeout time.Duration

// For the time-being Livepeer AI Subnet uses its own ServiceRegistry, so we define it here
ServiceRegistryAddr ethcommon.Address
}

func NewClient(cfg LivepeerEthClientConfig) (LivepeerEthClient, error) {

backend := NewBackend(cfg.EthClient, cfg.Signer, cfg.GasPriceMonitor, cfg.TransactionManager)

return &client{
accountManager: cfg.AccountManager,
backend: backend,
tm: cfg.TransactionManager,
controllerAddr: cfg.ControllerAddr,
checkTxTimeout: cfg.CheckTxTimeout,
accountManager: cfg.AccountManager,
backend: backend,
tm: cfg.TransactionManager,
controllerAddr: cfg.ControllerAddr,
checkTxTimeout: cfg.CheckTxTimeout,
serviceRegistryAddr: cfg.ServiceRegistryAddr,

Check warning on line 185 in eth/client.go

View check run for this annotation

Codecov / codecov/patch

eth/client.go#L180-L185

Added lines #L180 - L185 were not covered by tests
}, nil
}

Expand Down Expand Up @@ -211,28 +215,15 @@

glog.V(common.SHORT).Infof("LivepeerToken: %v", c.tokenAddr.Hex())

chainID, err := c.backend.ChainID(context.Background())
if err != nil {
glog.Errorf("Failed to get chain ID from remote ethereum node: %v", err)
return err
}

// TODO: This is a temporary setup for a separate AIServiceRegistry. Revise this when AI subnet merges with the mainnet.
var serviceRegistryAddr ethcommon.Address
arbitrumOneChainID := big.NewInt(42161)
if chainID.Cmp(arbitrumOneChainID) == 0 {
serviceRegistryAddr = ethcommon.HexToAddress("0x04C0b249740175999E5BF5c9ac1dA92431EF34C5")
} else {
serviceRegistryAddr, err = c.GetContract(crypto.Keccak256Hash([]byte("ServiceRegistry")))
if c.serviceRegistryAddr == (ethcommon.Address{}) {
c.serviceRegistryAddr, err = c.GetContract(crypto.Keccak256Hash([]byte("ServiceRegistry")))

Check warning on line 219 in eth/client.go

View check run for this annotation

Codecov / codecov/patch

eth/client.go#L218-L219

Added lines #L218 - L219 were not covered by tests
if err != nil {
glog.Errorf("Error getting ServiceRegistry address: %v", err)
return err
}
}

c.serviceRegistryAddr = serviceRegistryAddr

serviceRegistry, err := contracts.NewServiceRegistry(serviceRegistryAddr, c.backend)
serviceRegistry, err := contracts.NewServiceRegistry(c.serviceRegistryAddr, c.backend)

Check warning on line 226 in eth/client.go

View check run for this annotation

Codecov / codecov/patch

eth/client.go#L226

Added line #L226 was not covered by tests
if err != nil {
glog.Errorf("Error creating ServiceRegistry binding: %v", err)
return err
Expand Down
Loading