Skip to content

Commit

Permalink
Channel Funding Version 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DerEwige committed Nov 4, 2023
1 parent 273ff7f commit f810476
Show file tree
Hide file tree
Showing 6 changed files with 518 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Eclair-ChannelFundingPlugin/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
179 changes: 179 additions & 0 deletions Eclair-ChannelFundingPlugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fr.acinq.eclair.plugin</groupId>
<artifactId>ChannelFundingPlugin</artifactId>
<version>0.0.3</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.version>2.13.10</scala.version>
<scala.version.short>2.13</scala.version.short>
<eclair.version>0.9.0</eclair.version>
<akka.version>2.6.20</akka.version>
<akka.http.version>10.2.7</akka.http.version>
<sttp.version>3.8.5</sttp.version>
<bitcoinlib.version>0.28</bitcoinlib.version>
</properties>

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>false</addClasspath>
<mainClass>fr.acinq.ChannelInterceptor.ChannelFundingPlugin</mainClass>
</manifest>
</archive>
</configuration>

</plugin>


<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>fr.acinq.ChannelInterceptor.ChannelFundingPlugin</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>fr.acinq</groupId>
<artifactId>bitcoin-lib_${scala.version.short}</artifactId>
<version>${bitcoinlib.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>fr.acinq.eclair</groupId>
<artifactId>eclair-core_2.13</artifactId>
<version>${eclair.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>fr.acinq.eclair</groupId>
<artifactId>eclair-node_2.13</artifactId>
<version>${eclair.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.clapper</groupId>
<artifactId>grizzled-slf4j_2.13</artifactId>
<version>1.3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http_${scala.version.short}</artifactId>
<version>${akka.http.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-stream_${scala.version.short}</artifactId>
<version>${akka.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor-typed_${scala.version.short}</artifactId>
<version>${akka.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-native_${scala.version.short}</artifactId>
<version>3.6.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.softwaremill.sttp.client3</groupId>
<artifactId>json4s_${scala.version.short}</artifactId>
<version>${sttp.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.softwaremill.sttp</groupId>
<artifactId>okhttp-backend_${scala.version.short}</artifactId>
<version>1.7.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.71</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>

<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.39.3.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>

</dependencies>

</project>
7 changes: 7 additions & 0 deletions Eclair-ChannelFundingPlugin/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ChannelFundingPlugin

This is a plugin for eclair lightning node.
It lets you create rules for new incoming channels.

There is a sample config here:

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package fr.acinq.ChannelInterceptor;


import akka.actor.ActorSystem;
import akka.actor.typed.ActorRef;
import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.Adapter;
import akka.actor.typed.SupervisorStrategy;
import akka.actor.typed.javadsl.Behaviors;
import fr.acinq.eclair.InterceptOpenChannelCommand;
import fr.acinq.eclair.InterceptOpenChannelPlugin;
import fr.acinq.eclair.Kit;
import fr.acinq.eclair.NodeParams;
import fr.acinq.eclair.Plugin;
import fr.acinq.eclair.PluginParams;
import fr.acinq.eclair.Setup;
import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;

/**
* Intercept OpenChannel messages received by the node and respond by continuing the process
* of accepting the request, potentially with different local parameters, or failing the request.
*/
public class ChannelFundingPlugin implements Plugin {
final static Logger logger = LoggerFactory.getLogger(ChannelFundingPlugin.class);

private OpenChannelInterceptorKit pluginKit;
private File configFile;

@Override
public PluginParams params() {
return new InterceptOpenChannelPlugin() {
@Override
public String name() {
return "ChannelFundingPlugin";
}

@Override
public ActorRef<InterceptOpenChannelCommand> openChannelInterceptor() {
return pluginKit.openChannelInterceptor();
}
};
}

@Override
public void onSetup(Setup setup) {
File datadir = new File(setup.datadir().toPath().toAbsolutePath().toString());
File resourcesDir = new File(datadir,"/plugin-resources/ChannelFunding/");
configFile = new File(resourcesDir,"ChannelFunding.conf");
logger.info("Using config file: "+configFile.getAbsolutePath());

//we load the config once at startup to check if at least hte default accept rule is set
try {
Config PluginConf = ConfigFactory.parseFile(configFile).resolve();

@SuppressWarnings("unused")
boolean accept = PluginConf.getBoolean("open-channel-interceptor.default.accept");
@SuppressWarnings("unused")
long min_channel_size = PluginConf.getLong("open-channel-interceptor.default.min_channel_size");
@SuppressWarnings("unused")
long max_channel_size = PluginConf.getLong("open-channel-interceptor.default.max_channel_size");
@SuppressWarnings("unused")
int min_active_channels = PluginConf.getInt("open-channel-interceptor.default.min_active_channels");
} catch (Throwable e)
{
logger.error("Can not read default accept rules from config file");
logger.error(""+e);
}

logger.info("ChannelFundingPlugin finished startup");
}

@Override
public void onKit(Kit kit) {

ActorSystem actorSystem = kit.system();
Behavior<InterceptOpenChannelCommand> MyBehaviour = Behaviors.supervise(OpenChannelInterceptor.apply(configFile.getAbsolutePath(), Adapter.toTyped(kit.router())))
.onFailure(SupervisorStrategy.restart());

akka.actor.typed.ActorRef<InterceptOpenChannelCommand> openChannelInterceptor = Adapter.spawnAnonymous(actorSystem, MyBehaviour);


pluginKit = new OpenChannelInterceptorKit(kit.nodeParams(), kit.system(), openChannelInterceptor);

logger.info("ChannelFundingPlugin subscribed to events");
}

}

class OpenChannelInterceptorKit {
private final NodeParams nodeParams;
private final ActorSystem system;
private final ActorRef<InterceptOpenChannelCommand> openChannelInterceptor;

public OpenChannelInterceptorKit(NodeParams nodeParams, ActorSystem system, ActorRef<InterceptOpenChannelCommand> openChannelInterceptor) {
this.nodeParams = nodeParams;
this.system = system;
this.openChannelInterceptor = openChannelInterceptor;
}

public NodeParams nodeParams() {
return nodeParams;
}

public ActorSystem system() {
return system;
}

public ActorRef<InterceptOpenChannelCommand> openChannelInterceptor() {
return openChannelInterceptor;
}
}
Loading

0 comments on commit f810476

Please sign in to comment.